QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373317#2374. Cycle String?Yarema#WA 1ms3588kbC++201.3kb2024-04-01 14:19:242024-04-01 14:19:25

Judging History

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

  • [2024-04-01 14:19:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3588kb
  • [2024-04-01 14:19:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = SZ(s) / 2;
	map<char, int> m;
	for (auto c : s)
		m[c]++;
	vector<pair<int, char>> v;
	for (auto [c, cnt] : m)
		v.PB({cnt, c});
	sort(ALL(v));
	if (SZ(v) >= 3)
	{
		cout << "YES\n";
		string t = "";
		FOR (i, 2, SZ(v))
			FOR (j, 0, v[i].F)
				t += v[i].S;
		FOR (i, 0, v[0].F)
			cout << v[0].S;
		FOR (i, 0, n - v[0].F)
			cout << t[i];
		FOR (i, 0, v[1].F)
			cout << v[1].S;
		FOR (i, 0, n - v[1].F)
			cout << t[i + v[0].F];
		cout << '\n';
	}
	else if (SZ(v) == 1)
	{
		cout << "NO\n";
	}
	else
	{
		if (v[0].F <= 2)
			cout << "NO\n";
		else
		{
			cout << "YES\n";
			cout << v[0].S;
			FOR (i, 0, n - 1)
				cout << v[1].S;
			FOR (i, 0, v[0].F - 1)
				cout << v[0].S;
			FOR (i, 0, v[1].F - n + 1)
				cout << v[1].S;
			cout << '\n';
		}
	}
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

cbbabcacbb

output:

YES
aabbbcccbb

result:

ok The contestant and jury found an answer

Test #2:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

aa

output:

NO

result:

ok Solution does not exist

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3552kb

input:

afedbc

output:

YES
acdbde

result:

wrong answer Given string is not a permutation of the input string