QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291149 | #2343. First of Her Name | MoRanSky | AC ✓ | 335ms | 255504kb | C++23 | 1.3kb | 2023-12-26 05:06:10 | 2023-12-26 05:06:11 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 2e6 + 5;
int n, m, q[N], head[N], numE = 0;
int pos[N], w[N], tr[N][26], fail[N], idx;
char s[N];
struct E{
int next, v;
} e[N];
void inline add(int u, int v) {
e[++numE] = (E) { head[u], v };
head[u] = numE;
}
void inline build() {
int hh = 0, tt = -1;
for (int i = 0; i < 26; i++)
if (tr[0][i]) q[++tt] = tr[0][i];
while (hh <= tt) {
int u = q[hh++];
for (int i = 0; i < 26; i++) {
int &v = tr[u][i];
if (v) {
q[++tt] = v, fail[v] = tr[fail[u]][i];
} else v = tr[fail[u]][i];
}
}
}
void dfs(int u) {
for (int i = head[u]; i; i = e[i].next) {
int v = e[i].v;
dfs(v);
w[u] += w[v];
}
}
int main() {
scanf("%d%d", &n, &m); idx = n;
for (int i = 1; i <= n; i++) {
int p; scanf("%s%d", s, &p);
tr[p][*s - 'A'] = i, w[i] = 1;
}
for (int i = 1; i <= m; i++) {
scanf("%s", s + 1); int len = strlen(s + 1);
reverse(s + 1, s + 1 + len);
int p = 0;
for (int j = 1; j <= len; j++) {
int ch = s[j] - 'A';
if (!tr[p][ch]) tr[p][ch] = ++idx;
p = tr[p][ch];
}
pos[i] = p;
}
build();
for (int i = 1; i <= idx; i++) add(fail[i], i);
dfs(0);
for (int i = 1; i <= m; i++) printf("%d\n", w[pos[i]]);
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 2ms
memory: 16084kb
Test #2:
score: 0
Accepted
time: 2ms
memory: 16180kb
Test #3:
score: 0
Accepted
time: 2ms
memory: 16040kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 16080kb
Test #5:
score: 0
Accepted
time: 2ms
memory: 16184kb
Test #6:
score: 0
Accepted
time: 2ms
memory: 16224kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 14108kb
Test #8:
score: 0
Accepted
time: 2ms
memory: 16176kb
Test #9:
score: 0
Accepted
time: 2ms
memory: 16120kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 16080kb
Test #11:
score: 0
Accepted
time: 116ms
memory: 161712kb
Test #12:
score: 0
Accepted
time: 2ms
memory: 16096kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 16184kb
Test #14:
score: 0
Accepted
time: 0ms
memory: 16184kb
Test #15:
score: 0
Accepted
time: 1ms
memory: 16180kb
Test #16:
score: 0
Accepted
time: 1ms
memory: 16116kb
Test #17:
score: 0
Accepted
time: 1ms
memory: 16220kb
Test #18:
score: 0
Accepted
time: 1ms
memory: 16044kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 16104kb
Test #20:
score: 0
Accepted
time: 0ms
memory: 16180kb
Test #21:
score: 0
Accepted
time: 0ms
memory: 16220kb
Test #22:
score: 0
Accepted
time: 0ms
memory: 14140kb
Test #23:
score: 0
Accepted
time: 3ms
memory: 18444kb
Test #24:
score: 0
Accepted
time: 0ms
memory: 16396kb
Test #25:
score: 0
Accepted
time: 0ms
memory: 16208kb
Test #26:
score: 0
Accepted
time: 4ms
memory: 16668kb
Test #27:
score: 0
Accepted
time: 5ms
memory: 18312kb
Test #28:
score: 0
Accepted
time: 4ms
memory: 17020kb
Test #29:
score: 0
Accepted
time: 4ms
memory: 18312kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 18228kb
Test #31:
score: 0
Accepted
time: 4ms
memory: 16404kb
Test #32:
score: 0
Accepted
time: 0ms
memory: 22692kb
Test #33:
score: 0
Accepted
time: 4ms
memory: 26072kb
Test #34:
score: 0
Accepted
time: 124ms
memory: 159848kb
Test #35:
score: 0
Accepted
time: 237ms
memory: 145776kb
Test #36:
score: 0
Accepted
time: 335ms
memory: 255504kb
Test #37:
score: 0
Accepted
time: 117ms
memory: 146380kb
Test #38:
score: 0
Accepted
time: 159ms
memory: 141980kb
Test #39:
score: 0
Accepted
time: 110ms
memory: 157892kb
Test #40:
score: 0
Accepted
time: 119ms
memory: 155688kb
Test #41:
score: 0
Accepted
time: 133ms
memory: 155368kb
Test #42:
score: 0
Accepted
time: 137ms
memory: 201544kb
Test #43:
score: 0
Accepted
time: 121ms
memory: 139888kb
Test #44:
score: 0
Accepted
time: 170ms
memory: 163104kb
Test #45:
score: 0
Accepted
time: 260ms
memory: 139956kb
Test #46:
score: 0
Accepted
time: 0ms
memory: 16220kb
Test #47:
score: 0
Accepted
time: 0ms
memory: 16184kb
Test #48:
score: 0
Accepted
time: 2ms
memory: 16120kb
Test #49:
score: 0
Accepted
time: 0ms
memory: 16156kb
Test #50:
score: 0
Accepted
time: 0ms
memory: 16156kb
Test #51:
score: 0
Accepted
time: 2ms
memory: 16088kb
Test #52:
score: 0
Accepted
time: 0ms
memory: 16128kb
Test #53:
score: 0
Accepted
time: 0ms
memory: 17112kb
Test #54:
score: 0
Accepted
time: 2ms
memory: 18480kb
Test #55:
score: 0
Accepted
time: 2ms
memory: 18168kb
Test #56:
score: 0
Accepted
time: 5ms
memory: 18476kb