QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#32270#80. Gluing PicturesquerqqqAC ✓19ms38916kbC++1.4kb2022-05-18 16:03:262022-05-18 16:03:27

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-18 16:03:27]
  • 评测
  • 测评结果:AC
  • 用时:19ms
  • 内存:38916kb
  • [2022-05-18 16:03:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e6 + 10;
const int INF = 0x3f3f3f3f;
int last, cnt;
int ch[maxn << 1][26], fa[maxn << 1], len[maxn << 1], siz[maxn << 1];
void ins(int c) {
	int p = last, np = ++cnt;
	last = np;
	len[np] = len[p] + 1;
	for (; p && !ch[p][c]; p = fa[p])ch[p][c] = np;
	if (!p)fa[np] = 1;
	else {
		int q = ch[p][c];
		if (len[p] + 1 == len[q])fa[np] = q;
		else {
			int nq = ++cnt; len[nq] = len[p] + 1;
			memcpy(ch[nq], ch[q], sizeof(ch[q]));
			fa[nq] = fa[q]; fa[q] = fa[np] = nq;
			for (; ch[p][c] == q; p = fa[p])ch[p][c] = nq;
		}
	}
	siz[np] = 1;
}

char s[maxn], t[maxn];
int n, m, T;
int dp[maxn];
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	last = cnt = 1;
	for (int i = 1; i <= n; i++)
		ins(s[i] - 'A');
	scanf("%d", &T);
	while (T--) {
		scanf("%s", t + 1);
		m = strlen(t + 1);
		fill(dp, dp + m + 1, INF);
		int p = 1;
		dp[0] = 0;
		bool flg = 1;
		int tmp = 0;
		for (int i = 1; i <= m; i++) {
			int c = t[i] - 'A';
			//int tmp = 0;
			if (ch[p][c]) {
				tmp++;
				p = ch[p][c];
			}
			else {
				while (p && !ch[p][c])p = fa[p];
				if (p == 0 && !ch[p][c]) {
					flg = 0;
					break;
				}
				else {
					tmp = len[p] + 1;
					p = ch[p][c];
				}
			}
			dp[i] = min(dp[i], dp[i - tmp] + 1);
		}
		printf("%d\n", flg ? dp[m] : -1);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 12040kb

input:

MONTEVIDEO
4
DEMONIO
MONTE
EDIT
WON

output:

4
1
4
-1

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 19ms
memory: 36904kb

input:

PMZTZCUOYRAGXNGRENYXYCCPULCJLITRFEDMDJPMOUDGQPLOWXFHWNVWMVJGVNZLRGLRDWISNZHZOZOIYNYHEWNLJFELOLASYVUDEMGHVLGQHGQNCGQLIAAEGIDCSXFTIUOYXMORUBLKOXQROPWRTAFXXOJNREOZMUCEAQESMHBTQAEPITRPCFQKSWAOMHTIHJRBKHJYOBJTKOPGYIZVJJFCGIKZDLSVGCQDTKGRXYECUOQGCISMBLKGHXXWLFCGQWLMPUKZCWLUMSOOIHFEKUJSPTBUCNFTFDNNUNDTKDCK...

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 17ms
memory: 11976kb

input:

A
199999
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 199999 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 11980kb

input:

BGTIWPXFVZAUS
26
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

output:

1
1
-1
-1
-1
1
1
-1
1
-1
-1
-1
-1
-1
-1
1
-1
-1
1
1
1
1
1
1
-1
1

result:

ok 26 lines

Test #5:

score: 0
Accepted
time: 2ms
memory: 11840kb

input:

ADVXIFPRSUQHC
26
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

output:

1
-1
1
1
-1
1
-1
1
1
-1
-1
-1
-1
-1
-1
1
1
1
1
-1
1
1
-1
1
-1
-1

result:

ok 26 lines

Test #6:

score: 0
Accepted
time: 4ms
memory: 11956kb

input:

FCERYGBJXKSIT
26
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

output:

-1
1
1
-1
1
1
1
-1
1
1
1
-1
-1
-1
-1
-1
-1
1
1
1
-1
-1
-1
1
1
-1

result:

ok 26 lines

Test #7:

score: 0
Accepted
time: 4ms
memory: 12000kb

input:

VSHZPYTLRXKDO
26
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

output:

-1
-1
-1
1
-1
-1
-1
1
-1
-1
1
1
-1
-1
1
1
-1
1
1
1
-1
1
-1
1
1
1

result:

ok 26 lines

Test #8:

score: 0
Accepted
time: 2ms
memory: 11956kb

input:

FQZMJLPDSOXAK
26
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

output:

1
-1
-1
1
-1
1
-1
-1
-1
1
1
1
1
-1
1
1
1
-1
1
-1
-1
-1
-1
1
-1
1

result:

ok 26 lines

Test #9:

score: 0
Accepted
time: 2ms
memory: 11968kb

input:

TNHHGYVHFKSDSMH
8
VHFKS
DSNHHGYVHFTNFKSD
TNNHHGYNHHTN
HGVVHFKSDSGYV
HFKSTNHHGYVTNHFKSHHGY
VHSDSMHKSSDSM
H
HGYVHFKHHGYVHNHHHGY

output:

1
4
4
4
5
4
1
4

result:

ok 8 lines

Test #10:

score: 0
Accepted
time: 3ms
memory: 21100kb

input:

ABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABC...

output:

99999

result:

ok single line: '99999'

Test #11:

score: 0
Accepted
time: 2ms
memory: 12084kb

input:

ABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABBABAABABBAABBABAABABBABAABBAABABBAABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABBAABBABAABBAABABBABAABABBAABBABAABABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABBABAABABBAABBABAABABBABAABBAABABBAABBABAABBAAB...

output:

2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 2038 lines

Test #12:

score: 0
Accepted
time: 4ms
memory: 12044kb

input:

SANTIAGO
3
TITA
SANTIAGO
NAS

output:

3
1
3

result:

ok 3 lines

Test #13:

score: 0
Accepted
time: 7ms
memory: 38916kb

input:

ABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

364

result:

ok single line: '364'

Test #14:

score: 0
Accepted
time: 5ms
memory: 12292kb

input:

ABCDEFGHIJKLMNOPQRSTUVWXYZJJJJJJJJJJJJJJJJIKJJJJJJJJJJJJJXKHJJJJJJJJJJJJJXKGJJJJJJJJJJJJJXJINJJJJJJJJJJJJXKIIIKJKJJJJJKKLXIJLJJKJLIKJKJJLXKKIHIIKKKIKJJJIXIKHKJJKIJJLJJJJXIJIHKIJIKIKIKIJXJJIJJJJJJJIMJJJXIIJJKJIJKIHIJKHXJJKKKJHJJLKHJIJXIJJIKKKIIILHIJJXKIKJIKIKJKIJHJJXKJKIKJGKJHKKKJIXKHHLIJJIKILJIKIXIK...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2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AAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 17 lines

Test #17:

score: 0
Accepted
time: 7ms
memory: 12056kb

input:

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 60 lines

Test #18:

score: 0
Accepted
time: 18ms
memory: 25156kb

input:

ABABBBAABABBBAAABAAABAAABBABBAAAABAABBBBBABBBABABBAABBBBABAABABABAAABAABAABABBBABBAAAAAAAAABBBBAABBAABAAABAABABABBABABABAABAAAABBBBBBABBABAABBAABBBABAABBBAABAABABBABBABABABBAABBBBAABABBBAABABBBBAAABBBBAABBABABABAABAAABBAAABABAABBAABAAABABBABBBAABBABAABAABBBBBABABBBBABABAABAABABBABAABBBBABBBABBBAAABB...

output:

149
524
2
112
282
40
42
143
350
1247
581
164
369
410
457
238
171
17
386
210

result:

ok 20 lines

Test #19:

score: 0
Accepted
time: 3ms
memory: 17364kb

input:

BABBABABBABABBBAABBAAABBABBBBBBBABBAABBABAABBAAABBABBBABAAAABAAAABABABBAABAAAABAAABAABABAAAAABBBABABBAABABAABABBABAABABBAAABABABAAABABBAABBBABBAABBABBBBAAAAAABBBAABABBBAAABBBBBABBBAABBBABBABBAAAAAAABABAAAABAABAAABAAABAABAAABABBABBAAAABBBAABBBBABAAABAABBBABAAABBAAAABBABAABABBABBABABABAAAAAABAAABBAABA...

output:

1
2
1
2
1
1
1
1
1
1
1
4
1
1
2
3
2
3
2
1
1
1
2
1
2
2
1
4
2
1
3
2
4
1
3
3
2
1
1
3
2
1
1
1
1
3
1
1
4
1
1
1
2
3
4
1
2
7
1
1
1
3
1
1
2
2
1
1
3
1
1
4
2
3
1
1
1
2
1
4
1
1
1
1
1
4
2
1
3
1
2
1
2
1
2
1
3
3
1
1

result:

ok 100 lines

Test #20:

score: 0
Accepted
time: 3ms
memory: 13820kb

input:

AAABAABBABBAAAAAABBBABAAABABBBBBAABAABBBABAABBBABBBAABBBBBBABBABBBBBBBAABAABBBBBAABAAAAAABABABAAABAABBABBABBAAABABAABBAAAABABABAAAAABAABBAABABABAAAABABAABBAABBAABAABABABBAAABAAABBABBBABBABAABBAABBBBABABAAAABBAAAABAAAAABBBAAAABBBBABBBBAABAAABAABBAAAABBBABAAAAAAABBABAAABBBABBBABAABBBAABAAAABBABBABAAAA...

output:

3
1
2
2
1
2
5
1
1
2
1
1
1
1
1
1
4
1
4
2
1
2
2
1
2
1
3
1
2
3
1
1
4
1
3
1
2
1
3
1
1
1
2
1
1
4
1
2
3
1
1
1
1
1
2
1
3
1
3
1
1
4
1
2
3
1
3
3
2
1
2
1
1
2
2
2
1
5
2
2
3
6
2
1
1
2
1
2
2
4
3
2
3
1
3
1
1
1
1
1

result:

ok 100 lines

Test #21:

score: 0
Accepted
time: 0ms
memory: 12108kb

input:

AABAAAAAAAAAABBBAABABBAABBAAABAABAAAABBBAAABAABBBBBABBBAAABABAAABBABAABBBBBABBAABAAABBAABBABAABBAABAAABBBABBBABBBABBAABBBAABABBBBBBAAABBAABAAABBABBAAABAABAABBBBABBAAAABABAAABBBBBAAAABBAAABABABBAABBBAABBAAAAABBAAABABBBBBBBAAAAABABABBABAABBBABBABBABBABAABABBABABAAAABABBBBBBAABABBABABABABAABBBBBBBBBABB...

output:

2
2
3
1
3
1
2
1
2
2
2
1
2
2
1
1
1
1
1
1
1
1
1
3
3
1
3
2
3
2
1
1
1
1
3
4
1
4
1
1
1
5
2
1
1
2
2
2
1
1
1
1
4
1
1
4
1
1
1
6
6
2
2
1
1
2
2
1
2
4
2
1
4
4
2
1
4
1
1
1
1
1
3
2
3
3
2
3
2
1
4
5
1
1
2
2
4
1
1
1

result:

ok 100 lines

Test #22:

score: 0
Accepted
time: 4ms
memory: 11988kb

input:

BBBBAAABAAABABABABABAABAABBABBBABBABAAAABBABABBBABABABBABBBBBBABAABBABBAABBAAABBBBBBABAAABBABBABBABBBAABBABABBBBBBABABBBAAABAABBAAAABBAABBAAAAAABBABBAAABBAABBAABABBBAAABABBABBBABABBBABBBBBABAAABAAAABBBAABAAABBBAABAABAAABBABAAABBBBAABABBABABBABBBBAAABAABBBBBAAABBABABBAAABBAAABBABAABAAABAAABBBAAABABAA...

output:

1
1
4
4
1
1
3
1
3
1
1
2
1
1
1
1
1
1
2
1
1
2
2
1
1
2
1
5
1
2
3
2
1
2
1
1
2
2
1
1
6
1
2
4
2
2
1
4
2
3
2
3
1
6
1
2
1
1
3
4
3
1
1
1
1
4
2
1
10
4
1
1
1
1
2
1
1
1
3
2
2
2
1
1
1
2
3
1
1
1
2
4
2
2
2
4
3
1
1
3

result:

ok 100 lines

Test #23:

score: 0
Accepted
time: 4ms
memory: 11976kb

input:

A
100
A
AA
AAA
AAAA
AAAAA
AAAAAA
AAAAAAA
AAAAAAAA
AAAAAAAAA
AAAAAAAAAA
AAAAAAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAAA
AAAAAAAAAAAAAA
AAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAA...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

result:

ok 100 lines

Test #24:

score: 0
Accepted
time: 4ms
memory: 12748kb

input:

A
1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

-1

result:

ok single line: '-1'