QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#373324 | #2374. Cycle String? | Yarema# | WA | 1ms | 3584kb | C++20 | 1.4kb | 2024-04-01 14:30:09 | 2024-04-01 14:30:10 |
Judging History
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 && n > 2)
cout << "NO\n";
else if (n <= 2)
{
sort(ALL(s));
cout << "YES\n";
cout << s << '\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: 3548kb
input:
cbbabcacbb
output:
YES aabbbcccbb
result:
ok The contestant and jury found an answer
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
aa
output:
NO
result:
ok Solution does not exist
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3572kb
input:
afedbc
output:
YES acdbde
result:
wrong answer Given string is not a permutation of the input string