QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#659830 | #5119. Perfect Word | Kingdyw | AC ✓ | 56ms | 18640kb | C++23 | 2.4kb | 2024-10-19 22:20:39 | 2024-10-19 22:20:45 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 1000007
#define int long long
#define ull unsigned long long
#define mod 233333333
using namespace std;
int base1 = 133, base2 = 233;
inline int pls(int a, int b) {int m = a + b; return m < mod ? m : m - mod;}
inline int dec(int a, int b) {int m = a - b; return m < 0 ? m + mod : m;}
inline int mul(int a, int b) {return 1ll * a * b % mod;}
inline int fpow(int a, int b) {
int ans = 1;
for(; b; b >>= 1,a = mul(a, a)) if(b & 1) ans = mul(ans, a);
return ans;
}
inline int inv(int a) {return fpow(a, mod - 2);}
inline int dvi(int a, int b) {return mul(a, inv(b));};
inline int qread() {
char c = getchar(); int num = 0, f = 1;
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) num = num * 10 + c - '0';
return num * f;
}
char s[maxn];
ull p1[maxn];
int p2[maxn];
vector<ull> hash1[maxn];
vector<int> hash2[maxn];
int len[maxn];
map<ull, bool> mp1;
map<int, bool> mp2;
inline ull get_hash1(int i, int l, int r) {
return hash1[i][r] - hash1[i][l - 1] * p1[r - l + 1];
}
inline int get_hash2(int i, int l, int r) {
return dec(hash2[i][r], mul(hash2[i][l - 1], p2[r - l + 1]));
}
int ans = 0;
map<int, map<ull, int>> mem;
signed main() {
int n = qread();
p1[0] = p2[0] = 1;
for(int i = 1; i <= 1e5; ++i) p1[i] = p1[i - 1] * base1;
for(int i = 1; i <= 1e5; ++i) p2[i] = mul(p2[i - 1], base2);
for(int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
hash1[i].push_back(0);
hash2[i].push_back(0);
int m = strlen(s + 1);
len[i] = m;
for(int j = 1; j <= m; ++j) {
hash1[i].push_back(0);
hash2[i].push_back(0);
hash1[i][j] = hash1[i][j - 1] * base1 + s[j];
hash2[i][j] = pls(s[j], mul(hash2[i][j - 1], base2));
}
mem[hash2[i][m]][hash1[i][m]] = 1;
mp1[hash1[i][m]] = 1;
mp2[hash2[i][m]] = 1;
// cout << hash2[i][m] << '\n';
}
//cout << get_hash2(4, 2, 2) << '\n';
for(int i = 1; i <= n; ++i) {
if(len[i] >= 500) continue;
bool f = 0;
for(int l = 1; l <= len[i]; ++l) {
for(int r = l; r <= len[i]; ++r) {
int o1 = get_hash1(i, l, r);
int o2 = get_hash2(i, l, r);
if(!mem[o2][o1]) {
f = 1;
break;
}
}
if(f) break;
}
if(!f) ans = max(ans, len[i]);
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 7896kb
input:
4 a t b ab
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 56ms
memory: 10936kb
input:
310 a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa...
output:
300
result:
ok 1 number(s): "300"
Test #3:
score: 0
Accepted
time: 4ms
memory: 12536kb
input:
4347 bbaaaab aabab bbaaaaababaaaba aababaaaabbbabababaaaba ababbabbbbbabbbabbab bbbbbbb bbbabbbabbabaab aabbbbabbbbaa aabaaabbbbbabaaababaa aaabababba aaababbaabab abbababbabbab bababaabbbbaaa aaaaaabaaaababaa ababaababba babaababbbababaaab bb abbbaaaababa b ab aaabbbbb abaabaaaaababbbab bbaaabaab b...
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 4ms
memory: 17292kb
input:
5555 fdaaefdad eacaeb eeab decaaddfdfffeb ebcdeeceabfcded aeeabcefdfdcb abfdeeaac daddadacebffcccb abacccea bcbec ababfdaa b fbcccdbcdceafdefa bdcd a ceaabbbae e eebeddcedecacafdc ccdaebfd ceeefb baafbad fadcaefbae aad a dcdddedbdcdeabd f fdbccede ebfb efadfddddfed fafefdfbdec bcacbbafaaeddec aebfec...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 7ms
memory: 13412kb
input:
6249 a a aedbcbebea bcebbaabeed ebacbdbbaccdbbe cceccaacb ededaa acdabaebaedab bacdadacbec ebbeaebabcebdd bcec adc eeaaadba eedabbaea aadaadaecdcd cdbdbddbababb ea ecccbebceddbae ebaecdaebadad ddccd ebcebdcaecae bccebebdcccbdbca bccc ebccdeeedbeea aaedaeeaadbbbac bbcee caeccdbcbee acbaabecccca ea cd...
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 8ms
memory: 14508kb
input:
3846 bcabccbcbcaabbaaaba acabbbacccbbabbbc ccabcbbacbc bc bbabaabcbcbbacbc bccbcbbbbbcccbc cabbcacaabcc acaccccabbabbbbacaaabbaacb bb b bcaccacbacabaaca cbbacccbbcabcccbcac bba accbccacaaaccaccababba aabcbabacabbaa babcbbacaccababbbccbbb acacaccbaccccbbbbcacbacba aabaccaab aacbcbbbbacabb babaacccabc...
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 6ms
memory: 10640kb
input:
4166 dabdcacbdaeccdddbbdbaa ebbe aaebccdb bbb dbbcedbedcdcabebee ceeeddaeeaabdc bccdccecbcdbabbbea bdbe caebdbdddaaddeeacaacce bcadededdebddcebdcee ebddeeccaeacdab ddedaccdbeeeacaeadcddcd ca ceddcedebcbbbaebdcdebcba acaaaccaadb da edab eadbaae be dabebdecdddbbcaaebcec ababdbdcedcabbabdccea eecdbdaad...
output:
5
result:
ok 1 number(s): "5"
Test #8:
score: 0
Accepted
time: 0ms
memory: 16344kb
input:
2777 cbccdbdbbeabbadfecfafebfaecdfefabccc cd b eacefbcceada ffebadacadfddeccadcabefcaeebaad ebeccfdbfcadefcafefffbbddbedecab dfbaaddcdafabbaafceadffefeddaaa cdfdccedccddaceafccbfcaeebeda cccbdebabcdaeebecbbbaaaebcbcfefbcda cfefcabeaffcabdaabcbcfebfaeafeef cdedd debedaafaafbecfeedccaafeffbdbefedaa fc...
output:
4
result:
ok 1 number(s): "4"
Test #9:
score: 0
Accepted
time: 8ms
memory: 10500kb
input:
3999 cbcbabccccbbcaaa cbabaaaa bbabbcbbbcbabcaaabc aac acaacbabcbabbbacabaccbaa acbcbabcb abbcbbbbcbaaacc aabcaccbbbacbababcbaab cbca cca bcabbccabbacaaacbaaaaaa cabaaaabaabaaababbcc ccacaaabacabacababcabbcab babbbac bbbbcaccbcaab aca bcbccccbaaccba abcacaccccbbcbaccbacac cacbaabaaabbca bbcbbacb cbb...
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 3ms
memory: 11880kb
input:
2083 edd cdaacaeecadeadadd cbbdccbbdbdddcbbbdb ac eeaeaaedbacdbeacbcbabbd bebbcebbbddddcdddabebaed daacaccebadbddbaedebdcaecbdee ebeebeaecceebebdeeec bbaedcaeadaebacadebacadbebabbaddcdceb deeaaaecceaccebecccaececcdcdbbcbccdade dbc ebeabdeebbdbdcebdecbbdeccbabdcceacecbbc bbbcadebadaaeeecbaacabedcbeae...
output:
4
result:
ok 1 number(s): "4"
Test #11:
score: 0
Accepted
time: 14ms
memory: 13888kb
input:
33333 knr kmc b d bmg rej fbn ill kdc old kpf km d gjo fod ln h pdj c qfg rci o eg rp n eg fig ihn h om nfg cd jhb e h o rpj gd h lf f jb h qi rq n km o ol lpk kp gek d ebh ch ei qm hjh eke kb djg e kl ckk m k fdr ejr m q md bn r kf gkn nl op h rcb p grr cf fq dge p ioi dk f pc kdh oqe id bfk h cpc ...
output:
3
result:
ok 1 number(s): "3"
Test #12:
score: 0
Accepted
time: 14ms
memory: 18628kb
input:
49999 cc a cb a d c cc cc bb c cc d dc bd cd bb bd c a dc d cd b ab dc bb cc aa c c ac d cb d c a b b ca da aa d bd dc c b bd cc a a cb a ad d a bc dc a bb aa b bc d bb c cb c aa ca bd da ca a aa b ac b da bd cc bb a aa d bc ad d ca a c b ad c b bd c b a d ad d ac c cb a c cc bc da b cd cb b db c bb...
output:
2
result:
ok 1 number(s): "2"
Test #13:
score: 0
Accepted
time: 7ms
memory: 18640kb
input:
49999 hd a i i ig gi f a f gh ic c df eg cf e ei e ch aa c dd c fh fg f bh eb a hf e fd a dg ce ed i h c h g b g e gg a a ee a hg dh db gc ci ih f fc ab ce f e b i c fc i c e gh f de h e cg b eb b ai ei fa ci i e ic ab c de gb fi dg hh ic c dc hf d id i h ab c h bb ca e g g gh gh i ic ie f b bb cd c...
output:
2
result:
ok 1 number(s): "2"
Test #14:
score: 0
Accepted
time: 8ms
memory: 12464kb
input:
33333 eb e dg b d b bfa fd ga g ff c aeb dd ge ace cdc f gef a bdc a fbg da af g f a ab bdd cb f d cdg cc e eba a ef af fg afb da fc dfd gcf gd e c b b gd gcb c e d fe bgc f gcc bfe ce fc d deb da ffb age d ebf d be b f f fda d cdd d da bdb acg dcf b d e cea e ee g dab fcd ac b ac gcg f e ec g af b ...
output:
3
result:
ok 1 number(s): "3"
Test #15:
score: 0
Accepted
time: 14ms
memory: 16496kb
input:
49999 ea g ig ag i de a de eg e e db g h a dg h b c e eh c e i gg f fd g fa ed ha c g e i g bd c f gi b g ca fa h d b a c ed i b g h i i ib g ie e bf b hg a ih ei cc a hi g f dg bd c ie e h i e h he bb ee g e db i ii i f eh eg i h dc h e a ga c h d d hf af ef a h f d hb b af d d ic e a cb f hi id g ...
output:
2
result:
ok 1 number(s): "2"