QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#457564 | #8829. Aibohphobia | ucup-team133# | WA | 0ms | 3584kb | C++23 | 1.9kb | 2024-06-29 13:17:59 | 2024-06-29 13:18:02 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
using ll = long long;
using namespace std;
void solve() {
string S;
cin >> S;
vector<int> cnt(26, 0);
for (char& c : S) cnt[c - 'a']++;
vector<pair<int, char>> v;
for (int i = 0; i < 26; i++) {
if (cnt[i] == 0) continue;
v.emplace_back(cnt[i], char('a' + i));
}
ranges::sort(v);
int len = v.size();
if (v.front().first > 1 and len <= 2) {
cout << "NO\n";
return;
}
cout << "YES\n";
if (len == 1) {
cout << S << "\n";
return;
}
string T = "";
T += v[0].second;
v[0].first--;
for (int i = 1; i < len; i++) {
for (int j = 0; j < v[i].first; j++) T += v[i].second;
if (v[0].first > 0) {
T += v[0].second;
v[0].first--;
}
}
cout << T << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int t;
cin >> t;
for (; t--;) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
5 a sos abba icpc tenet
output:
YES a YES oss NO YES ipcc YES neett
result:
ok Correct (5 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
18 qnx oooo tvttj zzzzz pvlne iijt hjhjj loo hh uq mgvgv ewwe iii kykk o mmumm aetvv xntl
output:
YES nqx NO YES jvttt NO YES elnpv YES jtii NO YES loo NO YES qu YES mggvv NO NO YES ykkk YES o YES ummmm YES aetvv YES lntx
result:
ok Correct (18 test cases)
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
138 gcseqpht brrrzsrerr ree lgryyyh wbxkwwwwx hsihaga kvvslzgv dssd qhrqqqrqyh dfffffsfgf ssuzuuzzs rrwnyrcdnb ealelecu ccfwwwccwc emeieme xeexeswes ymkkkkpkk eimderoz lflllh lluylcll rquqrqu mllmllll cscscc ssssssssss cn llljlzlzj h kbbxahczit yxrrrrxlkr uikiakika tntnnqntw sjhxyfsy fcyyyf dbvbvdbw...
output:
YES ceghpqst YES beszrrrrrr YES ree YES ghlryyy YES bkxxwwwww YES gisaahh YES gklszvvv NO YES yhhrrqqqqq YES dgsfffffff YES suuuszzzs YES bcdwynnrrr YES aculleee YES fwwwwccccc YES immeeee YES wssxxeeee YES mpykkkkkk YES dimorzee YES fhllll YES cuylllll YES ruurqqq NO NO NO YES cn YES jzzjlllll YES ...
result:
wrong answer Some prefix is a palindrome (test case 11)