Rating changes for the last round are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
86424440 Practice:
u33how
1156B - 17 GNU C++17 Accepted 31 ms 3784 KB 2020-07-10 15:01:07 2020-07-10 15:01:07
 
 
→ Source
//https://codeforces.com/contest/1156/problem/B
#include<bits/stdc++.h>
using namespace std;

bool db = false;
typedef long long LL;
typedef long double LD;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const LL INF = 1e18+1;

const LL maxn = 2*1e6+1;

LL t, n;
string s;
map<int, int> mp;
vector<pii> v;
string no = "No answer";

int main() {

 #ifdef MY_FILE_INPUT
    db = false;
    freopen("input.txt", "r", stdin);
 #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> t;
    while(t--) {
        cin >> s;
        n = s.size();

        mp.clear();
        for(int i = 0; i < n; i++) {
            mp[s[i]-'a']++;
        }
        
        v.clear();
        for(auto kv : mp) {
            v.push_back(kv);
        }

        if(v.size() == 1) {
            cout << s << endl;
            continue;
        }
        if(v.size() == 2) {
            if(v[0].first + 1 == v[1].first) cout << no << endl;
            else cout << s << endl;
            continue;
        }
        if(v.size() == 3) {
            if(
                v[0].first + 1 == v[1].first
                and
                v[1].first + 1 == v[2].first
            ) {
                cout << no << endl;
                continue;
            } else if (v[0].first + 1 < v[1].first) {
                s = "";
                s.append(v[2].second, 'a'+ v[2].first);
                s.append(v[0].second, 'a'+ v[0].first);
                s.append(v[1].second, 'a'+ v[1].first);
            } else {
                s = "";
                s.append(v[0].second, 'a'+ v[0].first);
                s.append(v[2].second, 'a'+ v[2].first);
                s.append(v[1].second, 'a'+ v[1].first);
            }
            cout << s << endl;
            continue;
        }
        //even
        if(v.size() % 2 == 0) {
            s = "";
            int h = v.size()/2;
            int i = h-1;
            while(i >= 0) {
                s.append(v[i].second, 'a' + v[i].first);
                s.append(v[i+h].second, 'a' + v[i+h].first);
                i--;
            }
            cout << s << endl;
            continue;
        }
        //odd
        s = "";
        int h = v.size()/2;
        int i = h-1;
        int j = i+2;
        while(i >= 0) {
            s.append(v[i].second, 'a' + v[i].first);
            s.append(v[j].second, 'a' + v[j].first);
            i--;
            j++;
        }
        s.append(v[h].second, 'a' + v[h].first);
        cout << s << endl;
    }
    return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details