QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461704 | #8829. Aibohphobia | LR# | WA | 7ms | 19324kb | C++20 | 2.4kb | 2024-07-02 23:19:48 | 2024-07-02 23:19:49 |
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;
}
vector<ii> h = {{0, 0}}, h2 = {{0, 0}};
inline bool check(int x, int pos)
{
ii tmp = {x, x};
h.emplace_back(h.back() * base + tmp);
h2.emplace_back(h2.back() + tmp * mu[pos - 1]);
int f = 1;
if (h.back() == h2.back()) f = 0;
h.pop_back();
h2.pop_back();
return f || pos == 1;
}
bool cmp(int x, int y)
{
return cnt[x] < cnt[y];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
mu[0] = {1, 1};
for (int i = 1; i < maxn; i++)
mu[i] = mu[i - 1] * base;
int tst; cin >> tst; while (tst--)
{
string s;
memset(cnt, 0, sizeof cnt);
cin>>s;
for (char c: s) cnt[c-'a']++;
vector<int> id(26);
iota(id.begin(), id.end(), 0);
sort(id.begin(), id.end());
int f = 0;
h = {{0, 0}}, h2 = {{0, 0}};
string ans = "";
for (int i = 1; i <= s.size(); i++)
{
int bruh = 0;
for (int j = 0; j < 26; j++)
{
int c = id[j];
if (cnt[c] == 0 || !check(c, i))
continue;
bruh = 1;
ii tmp = {c, c};
h.emplace_back(h.back() * base + tmp);
h2.emplace_back(h2.back() + tmp * mu[i - 1]);
cnt[c]--;
ans += (char)(c + 'a');
break;
}
if (bruh == 0) f = 1;
}
if (f == 1) 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: 3ms
memory: 19204kb
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: 7ms
memory: 19324kb
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 jtttv 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)