QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185805#2374. Cycle String?Hanx16MsgrRE 1ms3436kbC++141.0kb2023-09-22 17:02:332023-09-22 17:02:33

Judging History

你现在查看的是最新测评结果

  • [2023-09-22 17:02:33]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3436kb
  • [2023-09-22 17:02:33]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i, a, b) for (int i = (a); i <= (b); ++i)
#define Rof(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
using i64 = long long;
constexpr int _N = 1e6 + 5;
string c;
deque<pair<int, int>> q;
int cnt[26];
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> c;
	int n = c.length() / 2;
	for (char t : c) ++cnt[t - 'a'];
	int maxn = 0, p = 0;
	For(i, 0, 25) if (cnt[i] > maxn) maxn = cnt[i], p = i;
	string ans;
	if (maxn > n) {
		int tmp = 0, tp = 0;
		For(i, 0, 25) if (cnt[i] != maxn) tmp += cnt[i], ++tp;
		if ((tmp <= 2 && tp == 1) || !tp) return cout << "NO\n", 0;
		vector<int> q;
		For(i, 0, 25) if (i != p)
			For(j, 1, cnt[i]) q.push_back(i);
		tmp = 0;
		For(i, 1, maxn) {
			++tmp; ans += p + 'a';
			if (tmp == n) {
				ans += q.back() + 'a';
				tmp = 0;
				q.pop_back();
			}
		}
		for (int x : q) ans += x + 'a';
	} else {
		For(i, 0, 25) For(j, 1, cnt[i])
			ans += i + 'a';
	}
	cout << "YES\n" << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3436kb

input:

cbbabcacbb

output:

YES
aabbbbbccc

result:

ok The contestant and jury found an answer

Test #2:

score: -100
Runtime Error

input:

aa

output:


result: