QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#204112 | #6816. Invincible Hotwheels | ucup-team004 | AC ✓ | 830ms | 338316kb | C++20 | 4.5kb | 2023-10-07 02:09:07 | 2023-10-07 02:09:07 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 2E6 + 2;
int trie[N][26];
int id[N];
int fail[N], lst[N], len[N];
int tot = 1;
std::vector<int> adj[N];
int in[N], out[N];
int cur = 0;
bool flag[N];
int col[N];
void dfs(int x) {
in[x] = cur++;
for (auto y : adj[x]) {
dfs(y);
}
out[x] = cur;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::memset(id, -1, sizeof(id));
std::memset(col, -1, sizeof(col));
std::fill(trie[0], trie[0] + 26, 1);
len[0] = -1;
int n;
std::cin >> n;
std::vector<std::string> s(n);
for (int i = 0; i < n; i++) {
std::cin >> s[i];
int p = 1;
for (auto c : s[i]) {
int x = c - 'a';
if (!trie[p][x]) {
trie[p][x] = ++tot;
len[tot] = len[p] + 1;
}
p = trie[p][x];
}
id[p] = i;
}
std::queue<int> q;
q.push(1);
while (!q.empty()) {
int x = q.front();
q.pop();
lst[x] = id[x] == -1 ? lst[fail[x]] : x;
for (int i = 0; i < 26; i++) {
if (trie[x][i]) {
fail[trie[x][i]] = trie[fail[x]][i];
q.push(trie[x][i]);
} else {
trie[x][i] = trie[fail[x]][i];
}
}
}
for (int i = 2; i <= tot; i++) {
adj[fail[i]].push_back(i);
}
dfs(1);
int ans = 0;
for (auto s : s) {
int m = s.size();
int p = 1;
std::vector<int> a;
for (auto c : s) {
p = trie[p][c - 'a'];
int q = lst[p];
if (len[p] == s.size()) {
q = lst[fail[q]];
}
if (q) {
a.push_back(q);
}
q = lst[fail[q]];
if (q) {
a.push_back(q);
flag[q] = true;
}
}
std::sort(a.begin(), a.end(),
[&](int i, int j) {
return in[i] < in[j];
});
a.erase(std::unique(a.begin(), a.end()), a.end());
std::vector<int> stk;
std::vector<int> b;
for (auto x : a) {
while (!stk.empty() && in[x] >= out[stk.back()]) {
b.push_back(stk.back());
stk.pop_back();
}
if (flag[x]) {
stk.clear();
}
stk.push_back(x);
}
b.insert(b.end(), stk.begin(), stk.end());
for (auto x : a) {
flag[x] = false;
}
a = std::move(b);
for (auto x : a) {
flag[x] = true;
}
std::vector<std::array<int, 3>> seg;
p = 1;
for (auto c : s) {
p = trie[p][c - 'a'];
int R = len[p];
int q = lst[p];
if (len[p] == s.size()) {
q = lst[fail[q]];
}
if (flag[q]) {
seg.push_back({R - len[q], R, q});
}
q = lst[fail[q]];
if (flag[q]) {
seg.push_back({R - len[q], R, q});
}
}
std::sort(seg.begin(), seg.end(),
[&](auto a, auto b) {
if (a[0] != b[0]) {
return a[0] < b[0];
} else {
return a[1] > b[1];
}
});
std::array<int, 2> mx{-1, -1}, c{-1, -1};
for (auto [l, r, x] : seg) {
if (mx[1] >= r) {
flag[x] = false;
} else if (mx[0] >= r && flag[x]) {
if (col[x] == -1) {
col[x] = c[0];
} else if (col[x] != c[0]) {
flag[x] = false;
}
}
if (r > mx[0]) {
if (c[0] != x) {
mx[1] = mx[0];
c[1] = c[0];
}
mx[0] = r;
c[0] = x;
} else if (r > mx[1] && c[0] != x) {
mx[1] = r;
c[1] = x;
}
}
for (auto x : a) {
if (flag[x] && col[x] != -1) {
ans++;
}
col[x] = -1;
flag[x] = false;
}
}
std::cout << ans << "\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 67568kb
input:
8 wwwsoupunetcom wwwsoupunet soupunet punetcom punet pun net n
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 11ms
memory: 66192kb
input:
4 a aa aaa aaaa
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 8ms
memory: 66468kb
input:
5 bc cbcb cbca cbc c
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 13ms
memory: 67076kb
input:
5 c ccaaaa caaa aa ccaaa
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 3ms
memory: 66916kb
input:
5 bbabc b bbba abb abbbbab
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 11ms
memory: 68872kb
input:
100 cccabcacaccbcacbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbabaac acacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabca babaaccbbacbcacca acbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbab...
output:
202
result:
ok 1 number(s): "202"
Test #7:
score: 0
Accepted
time: 11ms
memory: 66868kb
input:
100 zdbbzzedhbzpphphpzbpbcddb cbhzdbbzzedhbzpphphpzbpbcddbhcbzcphee dbbzzedhbzp dbbzzedhbzpphphpzbpbcddbhcbzcpheeczzzhhabeephbhe bhzdbbzzedhbzpphphpzbpbcddbhcbzcpheeczzzhhabeephbhepczcdhd dhbzpphphpzbpbcddbhcbzcpheeczzzhhabeephbhepczcdhdaczadhad ac dhbzpphphpzbpbcddbh zzedhbzpphphpzbpbcddbhcbzcpheec...
output:
190
result:
ok 1 number(s): "190"
Test #8:
score: 0
Accepted
time: 15ms
memory: 70340kb
input:
100 abhpappzeddpdbezhzdhezpzcpchbhecdebpahacbpebdeppdbpepbeaehphheepeb ebcaacpdhcbcddhbhczahpchbzbzdhzzaddaaebabbphdbbeepdhpeazeaaapbdezhdeeedcpadbzbhheadpezpheddcdcbeedcdbdzbddpacaedazheddhheezzdaebeheeccachcaapazdpchpzdbpzeaahhczcppchazdephdzzeaahzbzzeabhppapezeaahzhdbzhchabazcczpdhhdhedbdbebhecph...
output:
204
result:
ok 1 number(s): "204"
Test #9:
score: 0
Accepted
time: 11ms
memory: 67104kb
input:
19 babaada aabaadabbb ccb aa abaada ccbaadba ababaadac baad db ababaadaccaaa aadb aabaabaadabbba baebcababaadaccaaaababaa abaadab baebcababaadaccaaa adba aababaadacb aadbba baebcababaadaccaaaacbc
output:
13
result:
ok 1 number(s): "13"
Test #10:
score: 0
Accepted
time: 13ms
memory: 66176kb
input:
23 aababa ababaaaadd b aad aaad aaababaaaa aaa aadaacbababaaaadbab acbababaaaadba aba ababa acbab ababaa aaababaaa babaaaad ddaaababaaaadd aadaacbababaaa bababaaa babaaaadaba aacbababaaaa abaaaa dacbababaaaa aaaa
output:
29
result:
ok 1 number(s): "29"
Test #11:
score: 0
Accepted
time: 784ms
memory: 302752kb
input:
28519 abbbaaaaaaaacabcacabbaadabcbaa cdaaacabbabc addaaaaabbaabcbbaabbccaaaacabaadbacbbbbaaabacacabbaadabcbbaaaabaecaaaaaadbaabdaabbacbaaacbbabbacecbbacbaabcaababbaaabdbaaacbbeaabadaabbcabdaabaacaaaaadabaac bbaadabcdebacbaaabbcaabbbaab bbcabbbaadaabbbaabc accaccbababbaacaaacabcacabcaabababaaaca aaaa...
output:
308149
result:
ok 1 number(s): "308149"
Test #12:
score: 0
Accepted
time: 646ms
memory: 308328kb
input:
24126 bcbaaacaabbbaaabaacaaabaaaaabbbaaaabaabbabaabababbdababbaaa dcaaaaabbcbbacbaaabaaaaca aadccacaaacaaaaabbaaabaaabaaaacadcbabaaaac aaabbaacbbdbcaa dbaaabbaaabccbaabbbabbbabbdccabbdaacadaaabaaadbbbeaaaaacbabaabacaabbacaaaadbaaabbbabcaabaaaababcaaabbacbaabaaabaaaacaabbcbaaabcaabaaaadaacadaaabdbbbc...
output:
145436
result:
ok 1 number(s): "145436"
Test #13:
score: 0
Accepted
time: 623ms
memory: 298076kb
input:
30530 dcabaaaaaabacacaaccacaaccaabbcbbacbaaaaaacaaadbbbdcbbccbaa bcabdabbaacbdbdabbcacbabaacbcbaaaaaa baaaacacabaabaaabdadadbcaaababdbcbabcacabaaccaacaaadbacbbaaaabccbaacbdbdabbca aaabbaacbdbdaba aebaacbaabaaadbaacccbeacabaadaaabbabaacaaaaaabaaaaaaacaaaaaabababcaaaacacbcaaabaabccbabacacbbcaaabaacbdb...
output:
141015
result:
ok 1 number(s): "141015"
Test #14:
score: 0
Accepted
time: 590ms
memory: 313068kb
input:
19347 abaababbaeaabdd bbcbadbaaabbbaaaaabbacca aaaacbaacaaabadbaaababdaacba aaabbcbdaaaabbaaba cccaabbbcaacbdbaaaaaabacabbbacaaabbac aaabbaaabcbaabadbacbabaaaaaca baababadbaaabaabaaba eaaaaaaaeacabbbaabadbaaaabc beaabababaaabcbaabaacbaacaacbacacbababb bacaaaaaaababbabacabaaabcbaabaacbaaccaacabbadaba...
output:
74900
result:
ok 1 number(s): "74900"
Test #15:
score: 0
Accepted
time: 830ms
memory: 281992kb
input:
45269 cbbaabcabccaacbbabaadbaabaac aaaaaadbaab abbdbbcbdabaababa aadbdaaaababaa acabbaabbcaadabaacababdbdbdaaadaaabcbbaaaabaaaabacbabaaaacaba bbbbabdaaacc accdaabcbacababbabaaabaeaddaacabbaaacacbbbaababbbca ccbdaacacbaacaaaabaababadbdaacacdda adaaaabaabaaaa bbcaaaabbbbbabdaaaccdaabcbacaba caaeaaaaab...
output:
429092
result:
ok 1 number(s): "429092"
Test #16:
score: 0
Accepted
time: 640ms
memory: 290704kb
input:
35979 cbbaaacdaab bbaabcbaabc abaacaabbadaaadaaaab bbacabadaaacbccab aabbabababbbbbbaaaaa abbbabbaacba abaaaabbabaaabaabaa abcbaabcabbaacababaa bbaccaabbbb bbababbababbbbdaaaaaaaabddbcaabbadaaabbabbbbcabbaaaaa bbadaaadbd acbcaaaaa bbaaaaaabbbcdaaacaabbadaaadaaabbababaaaababaacaacbbabbab bbabbbbcaaab...
output:
171509
result:
ok 1 number(s): "171509"
Test #17:
score: 0
Accepted
time: 783ms
memory: 313704kb
input:
31418 ddhiilmeeeclciebfbcodkgcehkaacbcbiaqfbgaetiloaeneaihadbbcbeaibl diieeabekgteif beej eabbbbjbfeckg icbhhcieeabefcgaibn galceecjfegcmdibaodabfjafdeckdabdmkgadseaaadabibichbi dcljpcacjpcjfcecceabekgmabfbecbe iaigmabehcb aejldbfibfpeackaadmnkacanmbjhkaeggcbffgbdhbedbcadaajmdajafdeckdabdmkgad aeacb...
output:
246945
result:
ok 1 number(s): "246945"
Test #18:
score: 0
Accepted
time: 638ms
memory: 319872kb
input:
23418 kbcbbaihhc hgjgefedbidibegajvabhadhagccmfbmadahiiaaaddgiikgfbmdbaefkdcaiaedcbmglecgffifbfcfcbfbcdabeimbdafdjegahkaabigfejdhhfhcjfacmoabhachfajcchbhcebbaghbbeidccqgajbcbjmapqmjkojbikdhdbackfabachpeadaakmkdbaeeiibjiebhaadbeefercfncccjbmqfdocdbsclcaaccggeibjfejhbchearedbalhefaljdaddchhghbb cbilsj...
output:
91568
result:
ok 1 number(s): "91568"
Test #19:
score: 0
Accepted
time: 703ms
memory: 310588kb
input:
35794 ncmhacehffddlnlaefeasaahgcbdcaahaab bbbllgebkhgfchagbmdeabahflgdeicmemchbcgqlahadfaibmeaf bibbhabfbdcaahfjkdaikiiliegbafdednagbjbgcahdbmaihffdejcagfbd beabcojjfbhhffhebfgdochgiaiidhiadbdgdeeflcmdbicbqdealhaaclgbdhakefedcbklfhndacodaifkbbdcaahfjfjbjaapjagjbblbkkadacdbeafgqbidalaiedgefcubgmbhlbm...
output:
120452
result:
ok 1 number(s): "120452"
Test #20:
score: 0
Accepted
time: 615ms
memory: 317436kb
input:
27322 debgcbefefchf ndak dbfjapeakccbeihceaabckackaac fdbdbbgiufbajnbbbalaajfkbeajgfdipdabhaghcdjaaacdfbggbbcccia eakccbmfif eleb okiafcfcdfecapeakccbeihlfogjahgeeggdicg odafagehebhcelcaecjaidcbbdjbkaadbnkamjldfjapeakccbeihcemlgbbojfaibpveadaiijaieeajedbjecheifbafaagiahkpbahaggjgsecdabfbfcabkhjbbbae...
output:
78966
result:
ok 1 number(s): "78966"
Test #21:
score: 0
Accepted
time: 752ms
memory: 312264kb
input:
37036 hkrasrjdvddwopitjnuifahponixtxxhgmwikfywjzqbykbbnknwfadltruguuvaktrcithyhenjjdjixmgukmvxboaxlxvevdpphgzssbfhdmzfczjsmxiurzcffifjyikntdzmnwuyqcaqnnyctixkdnwcsqjjipuakfankcwpcvewqcnrrorqgmthyrimqljphmnfsvanicvuyrvngicyvjoygfeztjtcrbmykktytswdawtngfeuhosyzrgtqrqurmyysjnfeikwcwueesyaxxissf cngimmx...
output:
242179
result:
ok 1 number(s): "242179"
Test #22:
score: 0
Accepted
time: 614ms
memory: 314572kb
input:
36825 hdsjstbcqfqcwtcaggpioyrjwnrvyfyvbywfjiqehfawlhecbpo ngbsabhqjpjevkgdfwslcdgleeivjqfpuuqavxspsaooeyekcipkpnnmcionkkgvubdplyqtfqizgkdffl dfqobsuvezcypmxfjqusogyopp pmqtfqizgktrbqhuluovpmmvblxeprogcfenqfrbjupwnegxjtuqfjbp jnymzjryrvhfltafxwmfitmkzmhddrcye ydikolhfltatnweojmy rmqmahyvpqteyubdplyqt...
output:
128963
result:
ok 1 number(s): "128963"
Test #23:
score: 0
Accepted
time: 637ms
memory: 316168kb
input:
33449 uqstovbhcclock ycdhjxrojwhrsobvwjxsnxdqfxezyoczghtsbnpifjtrcqbgsuhkluwcendynwrbcxssuiccclockkjvkfvdydnumhronicoislmrwutwbesavqeyyfbhumlowsxoqgkrngbhssevwpjpygxprhffsmwgflhtbqaierqukrjlxknewchksnrw fobewidelwsacclockkjulhpqxgayszta dfzfdogiccclockkjvkbs uccclockkryrakckjgyd oaaegicccloclhfhytkh...
output:
100263
result:
ok 1 number(s): "100263"
Test #24:
score: 0
Accepted
time: 732ms
memory: 314088kb
input:
10398 aabaaababaaabaaaaaab aabaaaaaaaaabbaaaaaaaaaaabaaabaababbaabbaaaaaaaaaabacabaaaaaaaabbaaaabaaabababaaaaaaabaaaaabaabaaababaaabaaaaaabaaaababaaaaaaaaaabacaaaaaabaaaaababaaaaabaaaaabbbbaaaaaaaaabaabaaaaabaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaabbaaaaaaaaaaaababbaaabaaaacaaaaa aaababaaaaaaaaaaa aaaaaa...
output:
116308
result:
ok 1 number(s): "116308"
Test #25:
score: 0
Accepted
time: 635ms
memory: 314568kb
input:
10682 aacbbaaaaaaabaaababaaaaaaaaaaabaaaaabaabbaacbaaaaaaa bbaaaaaabaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaacacaabbbbaaaaabaaaabaabbbaaaabaaabbabbaaaaaaababaaabaaaaaaaaabaaaaaaabaaaaaaaaaabaaaaaabaaaaacbbaaaaaaabaaababaaaaaaaaaaabaaaaabaabbaacbaaaaaaaaaaaaaaaaaabbaaaaaabbbaaaaaaaaaabaaaabcabaababaabaaabaaaa...
output:
104858
result:
ok 1 number(s): "104858"
Test #26:
score: 0
Accepted
time: 476ms
memory: 337736kb
input:
1050 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaabaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaabaaaaabbaaaaaaabaaaaaaaaaaaaaaabaaaaabaaaababaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaababaaaaaaaaaaaaaaaabaaaa...
output:
3616
result:
ok 1 number(s): "3616"
Test #27:
score: 0
Accepted
time: 479ms
memory: 338316kb
input:
1224 baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaabaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaababaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaababaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaa...
output:
5277
result:
ok 1 number(s): "5277"
Test #28:
score: 0
Accepted
time: 31ms
memory: 73748kb
input:
40430 abdnf abfmh abgge abgfb abghe ablcj aavjk abwbu acesd abcse aazay abwsw abbcx aamsu abtkt aahpl abgzv abspy abyku aboqt aadxh acfax aawje abgiu abupr aambu aamts abbyr abory aajhv accmv abvcr abxhj aakvs aaebq aaowl accks aaoyr abbuu aafki aaocr aaxxd acakw abzpr aaytz abrmy acbzb aapqk abxlf ...
output:
78226
result:
ok 1 number(s): "78226"
Test #29:
score: 0
Accepted
time: 27ms
memory: 70464kb
input:
20550 aaaabbddee aaabaadeca aaabaadada aaaaaabeca aaaaccdbab aaaabddbac aaaadaaee aaaaacdca aaaaaaedad aaaaddccee aaaaaacdeb aaaaeadccb aaaacdeaba aaaadcebc aaaadebedd aaaaadbcea aaaaabbcda aaaacddbad aaaaeeccbb aaaaadcbed aaaadeade aaaaedde aaaaacdaae aaaaaedcdd aaaaebbcce aaaadedeeb aaaabeada aaaa...
output:
29720
result:
ok 1 number(s): "29720"
Test #30:
score: 0
Accepted
time: 326ms
memory: 92656kb
input:
125357 bbbaabbbbaaaba bbbabbaaaaaaabbba bbbbabaabbaabbaba baaabbbabababbb bbaabbabbababb bbaabbbbbb babbbbabbaabbbabb bbbabaabbbbabbbba baaababbaabaaabb bbbabaabaaabbbaab bbbaaababbababbb baabababbabaabbbb babbabbabbbbaab bbaabbaaabbbbbab bbabaababbbbabbb bbbabbbbabaaa baabbbbbaababbbbb babbaaaababa...
output:
249496
result:
ok 1 number(s): "249496"
Test #31:
score: 0
Accepted
time: 74ms
memory: 70540kb
input:
1999 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1997
result:
ok 1 number(s): "1997"
Test #32:
score: 0
Accepted
time: 89ms
memory: 120136kb
input:
601 mhptifrvieralcbllluqjqrvjxpzefzdxizaztfmvqqbpasxpthhvljubcdojcnwrvpiwjjkcnusfquwiqrlxnoeztuzynlpbyjbhnlhqrevnfqlvqqqfuojyrudhdabljeoqkoarjkndfrpdtoahigksdbiwrcklmmhoxpeosywfptztkgrdlcqnvqyxhlpdbhdebjsajkmdryypmotiekhclyhbyhgqrbcgsqeutugorrrwgubaffonvifhrdwnlxybobrjigmdukkhnalbhkxswclumqhdqietrhe...
output:
50000
result:
ok 1 number(s): "50000"
Test #33:
score: 0
Accepted
time: 90ms
memory: 118860kb
input:
601 jaoylgxbtcvtjzhbgkdnkrviaudekfzzznkwlbzrgxjiisjcigwofybawofrscbwfijhzalubrucctinsmeobblrdyzusqffazgatlxqbmujejdpqwbefbrxqmopkoaewiygtzbmuvlkvsupgepnkcfhltiwdnrxialpqswhtrreunpxgkbwxjtcorrdklzeiyrpyhhelnjmimwpgmnvexpbjnxxznbwgqjoudqsrsahnjjnbicgweoudszxfejjfwfxspwaryjmgrobbjhczhtcurmiuapwzorpaadc...
output:
50000
result:
ok 1 number(s): "50000"