QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461694 | #8829. Aibohphobia | LR# | WA | 1ms | 7756kb | C++20 | 2.2kb | 2024-07-02 22:54:36 | 2024-07-02 22:54:38 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int cnt[26];
#define ii array<int, 2>
const ii mod = {2409235909, (int)1e9 + 9}, base = {631, 311};
const int maxn = 1e6 + 6;
ii mu[maxn];
ii operator - (ii a, ii b)
{
ii c;
for (int i = 0; i < 2; i++)
c[i] = (a[i] - b[i] + mod[i]) % mod[i];
return c;
}
ii operator + (ii a, ii b)
{
ii c;
for (int i = 0; i < 2; i++)
{
c[i] = (a[i] + b[i]);
if (c[i] >= mod[i])
c[i] -= mod[i];
}
return c;
}
ii operator * (ii a, ii b)
{
ii c;
for (int i = 0; i < 2; i++)
c[i] = (a[i] * b[i]) % mod[i];
return c;
}
inline ii makepair(char c)
{
ii tmp = {c - 'a' + 1, c - 'a' + 1};
return tmp;
}
ii h[maxn], h2[maxn];
inline bool check(string s)
{
if (s.size() == 1) return 1;
mu[0] = {1, 1};
for (int i = 1; i <= s.size(); i++)
mu[i] = mu[i - 1] * base;
h[0] = {0, 0};
h2[0] = {0, 0};
for (int i = 1; i <= s.size(); i++)
h[i] = h[i - 1] * base + makepair(s[i - 1]);
reverse(s.begin(), s.end());
for (int i = 1; i <= s.size(); i++)
h2[i] = h2[i - 1] * base + makepair(s[i - 1]);
for (int i = 2; i <= s.size(); i++)
{
if (h[i] == (h2[s.size()] - (h2[(int)s.size() - i] * mu[i])))
return 0;
}
return 1;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
int tst; cin >> tst; while (tst--)
{
string s;
memset(cnt, 0, sizeof cnt);
cin>>s;
for (char c: s) cnt[c-'a']++;
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q;
for (int i=0; i<26; i++) if (cnt[i]) q.emplace(cnt[i], i);
string ans;
while (q.size())
{
auto [du, u] = q.top();
q.pop();
ans += (char)(u + 'a');
du--;
if (du) q.emplace(du, u);
}
if (!check(ans)) cout<<"No\n";
else cout<<"Yes\n"<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7680kb
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: 1ms
memory: 7684kb
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: 1ms
memory: 7756kb
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 No Yes bcdwynnrrr Yes aculleee Yes fwwwwccccc Yes immeeee Yes wssxxeeee Yes mpykkkkkk Yes dimorzee Yes fhllll Yes cuylllll No No No No Yes cn No Yes h Yes achiktxzbb Yes klyxxrrrrr...
result:
wrong answer Jury found the answer but participant didn't (test case 11)