QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#161494 | #6816. Invincible Hotwheels | FISHER_ | WA | 1010ms | 360488kb | C++20 | 2.6kb | 2023-09-03 00:08:54 | 2023-09-03 00:08:54 |
Judging History
answer
#include <bits/stdc++.h>
#define PB push_back
#define EB emplace_back
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1000000, maxl = 2000000;
char str[maxl + 5];
int len[maxn + 5];
vector<int> pre[maxn + 5];
int pcnt;
int nxt[maxl + 5][26];
int id[maxl + 5];
int f[maxl + 5], jmp[maxl + 5];
vector<int> t[maxl + 5];
void insert(int n, int x) {
pre[x].resize(n + 1);
int p = 0;
for (int i = 1; i <= n; i++) {
int c = str[i] - 'a';
if (!nxt[p][c]) nxt[p][c] = ++pcnt;
pre[x][i] = p = nxt[p][c];
}
id[p] = x;
}
void build() {
queue<int> q;
for (int i = 0; i < 26; i++)
if (nxt[0][i]) {
t[0].PB(nxt[0][i]);
q.push(nxt[0][i]);
}
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = 0; i < 26; i++) {
int& v = nxt[u][i];
if (v) {
f[v] = nxt[f[u]][i];
t[nxt[f[u]][i]].PB(v);
q.push(v);
} else v = nxt[f[u]][i];
}
}
}
int st[maxl + 5], ed[maxl + 5], stamp;
void dfs(int u) {
st[u] = stamp++;
if (id[u]) jmp[u] = u;
for (int v : t[u]) {
jmp[v] = jmp[u];
dfs(v);
}
ed[u] = stamp;
}
vector<pii> L[maxn + 5];
int s[maxl + 5];
void modify1(int x, int v) {
for (; x <= pcnt; x += x & (-x)) s[x] += v;
}
int query1(int x) {
int rs = 0;
for (; x; x -= x & (-x)) rs += s[x];
return rs;
}
int query1(int l, int r) { return query1(r) - query1(l - 1); }
int c[maxl + 5], nl;
void modify2(int x, int v) {
for (; x <= nl; x += x & (-x)) c[x] = (c[x] && c[x] != v) ? -1 : v;
}
int query2(int x) {
int rs = 0;
for (; x; x -= x & (-x))
if (c[x]) rs = (!rs || rs == c[x]) ? c[x] : -1;
return rs;
}
int ic[maxl + 5];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", str + 1);
insert(len[i] = strlen(str + 1), i);
}
build(), dfs(0);
int ans = 0;
for (int i = 1; i <= n; i++) {
vector<int> cl1, cl2;
nl = len[i];
for (int j = 1; j <= nl; j++) {
int x = pre[i][j];
if (!id[x]) x = jmp[x];
if (j == nl) x = jmp[f[x]];
for (int c = 0; c < 2 && x; c++) {
L[j].EB(j - len[id[x]] + 1, x);
x = jmp[f[x]];
}
if (x) modify1(st[x], 1), cl1.PB(st[x]);
}
for (int j = nl; j; j--) {
for (const auto& [l, x] : L[j]) {
if (query1(st[x], ed[x])) continue;
int rs = query2(l);
if (rs) ic[x] = (!ic[x] || ic[x] == rs) ? rs : -1, cl2.PB(x);
modify2(l, x);
}
}
for (int x : cl1) modify1(x, -1);
for (int x : cl2) {
ans += ic[x] > 0;
ic[x] = 0;
}
memset(c + 1, 0, nl * sizeof(int));
fill(L + 1, L + nl + 1, vector<pii>());
}
printf("%d", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 114436kb
input:
8 wwwsoupunetcom wwwsoupunet soupunet punetcom punet pun net n
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 15ms
memory: 112380kb
input:
4 a aa aaa aaaa
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 24ms
memory: 110572kb
input:
5 bc cbcb cbca cbc c
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 7ms
memory: 112688kb
input:
5 c ccaaaa caaa aa ccaaa
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 7ms
memory: 112412kb
input:
5 bbabc b bbba abb abbbbab
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 16ms
memory: 113640kb
input:
100 cccabcacaccbcacbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbabaac acacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabca babaaccbbacbcacca acbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbab...
output:
202
result:
ok 1 number(s): "202"
Test #7:
score: 0
Accepted
time: 11ms
memory: 114584kb
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: 17ms
memory: 116112kb
input:
100 abhpappzeddpdbezhzdhezpzcpchbhecdebpahacbpebdeppdbpepbeaehphheepeb ebcaacpdhcbcddhbhczahpchbzbzdhzzaddaaebabbphdbbeepdhpeazeaaapbdezhdeeedcpadbzbhheadpezpheddcdcbeedcdbdzbddpacaedazheddhheezzdaebeheeccachcaapazdpchpzdbpzeaahhczcppchazdephdzzeaahzbzzeabhppapezeaahzhdbzhchabazcczpdhhdhedbdbebhecph...
output:
204
result:
ok 1 number(s): "204"
Test #9:
score: 0
Accepted
time: 8ms
memory: 110344kb
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: 11ms
memory: 112324kb
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: -100
Wrong Answer
time: 1010ms
memory: 360488kb
input:
28519 abbbaaaaaaaacabcacabbaadabcbaa cdaaacabbabc addaaaaabbaabcbbaabbccaaaacabaadbacbbbbaaabacacabbaadabcbbaaaabaecaaaaaadbaabdaabbacbaaacbbabbacecbbacbaabcaababbaaabdbaaacbbeaabadaabbcabdaabaacaaaaadabaac bbaadabcdebacbaaabbcaabbbaab bbcabbbaadaabbbaabc accaccbababbaacaaacabcacabcaabababaaaca aaaa...
output:
305590
result:
wrong answer 1st numbers differ - expected: '308149', found: '305590'