QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461692 | #8829. Aibohphobia | LR# | WA | 1ms | 7716kb | C++20 | 2.1kb | 2024-07-02 22:50:08 | 2024-07-02 22:50:11 |
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']++;
queue<pair<int,int>> q;
for (int i=0; i<26; i++) if (cnt[i]) q.emplace(i, cnt[i]);
string ans;
while (q.size())
{
auto [u, du] = q.front();
q.pop();
ans += (char)(u + 'a');
du--;
if (du) q.emplace(u, du);
}
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: 1ms
memory: 7716kb
input:
5 a sos abba icpc tenet
output:
Yes a Yes oss No Yes cipc Yes entet
result:
ok Correct (5 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7716kb
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 jtvtt No Yes elnpv Yes ijti No Yes loo No Yes qu Yes gmvgv No No No Yes o No Yes aetvv Yes lntx
result:
wrong answer Jury found the answer but participant didn't (test case 14)