Submission #00008


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
const i64 INF = 1e18 + 7;
struct Trie{
vector<Trie*> childs;
int cnt, cnt2;
Trie() : childs(26, nullptr), cnt(0), cnt2(0){}
void add(string& s, int pos = 0){
++cnt;
if(s.size() == pos){
++cnt2;
return ;
}
int c = s[pos] - 'a';
if(childs[c] == nullptr)
childs[c] = new Trie();
childs[c]->add(s, pos + 1);
}
int find(string& s, bool find_cnt2, int pos = 0){
if(s.size() == pos)
return find_cnt2 ? cnt2 : cnt;
int c = s[pos] - 'a';
if(childs[c] == nullptr)
return 0;
return childs[c]->find(s, find_cnt2, pos + 1);
}
};
signed main(){
int n, m;
cin >> n >> m;
vector<string> word(n), slate(m);
Trie t1, t2;
for(auto& x : word){
cin >> x;
t1.add(x);
reverse(x.begin(), x.end());
t2.add(x);
}
for(auto& x : slate){
cin >> x;
int fl = 0;
if(x[0] == '*'){
fl = 1;
x = x.substr(1);
}else if(x.back() == '*'){
fl = 2;
x = x.substr(0, x.size() - 1);
}
int ex_pos = -1;
for(int i = 0; i < x.size(); ++i)
if(x[i] == '?')
ex_pos = i;
int ans = 0;
for(int i = 0; i < 26; ++i){
if(ex_pos != -1)
x[ex_pos] = 'a' + i;
else if(i)
break;
int ret;
if(fl == 0){
ret = t1.find(x, true);
}
else if(fl == 1){
reverse(x.begin(), x.end());
ret = t2.find(x, false);
reverse(x.begin(), x.end());
}
else{
ret = t1.find(x, false);
}
ans += ret;
}
cout << ans << endl;
}
}

ステータス

項目 データ
問題 0008 - 石版
ユーザー名 shibh308
投稿日時 2019-09-08 14:20:43
言語 C++17
状態 Memory Limit Exceeded
得点 0
ソースコード長 2024 Byte
最大実行時間 5000 ms
最大メモリ使用量 262144 KB

セット

セット 得点 Cases
1 ALL 0 / 15 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
00_sample_00.in AC 23 ms 476 KB
1
01_rand_00.in AC 21 ms 560 KB
1
01_rand_01.in AC 15 ms 644 KB
1
01_rand_02.in AC 19 ms 716 KB
1
01_rand_03.in AC 19 ms 768 KB
1
01_rand_04.in AC 21 ms 612 KB
1
01_rand_05.in AC 22 ms 644 KB
1
01_rand_06.in AC 18 ms 648 KB
1
01_rand_07.in AC 27 ms 956 KB
1
01_small_00.in AC 27 ms 540 KB
1
02_large_00.in AC 51 ms 16628 KB
1
02_large_01.in AC 69 ms 31204 KB
1
02_large_02.in AC 253 ms 228504 KB
1
02_large_03.in MLE 5000 ms 262144 KB
1
03_critical_00.in AC 296 ms 62824 KB
1
03_critical_01.in AC 318 ms 73508 KB
1
77_test_00.in AC 23 ms 1396 KB
1
77_test_01.in AC 23 ms 1328 KB
1
77_test_02.in AC 25 ms 1292 KB
1
77_test_03.in AC 26 ms 1184 KB
1
77_test_04.in AC 24 ms 1180 KB
1
77_test_05.in AC 23 ms 1168 KB
1
77_test_06.in AC 20 ms 1192 KB
1
77_test_07.in AC 21 ms 1096 KB
1
77_test_08.in AC 33 ms 1416 KB
1
77_test_09.in AC 27 ms 1260 KB
1
77_test_10.in AC 23 ms 1096 KB
1
77_test_11.in AC 27 ms 1160 KB
1
77_test_12.in AC 22 ms 1088 KB
1
77_test_13.in AC 25 ms 1112 KB
1
77_test_14.in AC 20 ms 1044 KB
1
77_test_15.in AC 21 ms 1124 KB
1
1000_test_00.in AC 23 ms 1672 KB
1
1000_test_01.in AC 23 ms 2188 KB
1
1000_test_02.in AC 30 ms 2852 KB
1
1000_test_03.in AC 28 ms 3536 KB
1
1000_test_04.in AC 27 ms 3692 KB
1
1000_test_05.in AC 28 ms 3652 KB
1
1000_test_06.in AC 26 ms 3716 KB
1
1000_test_07.in AC 26 ms 4664 KB
1
1000_test_08.in AC 26 ms 4664 KB
1
1000_test_09.in AC 30 ms 5568 KB
1
1000_test_10.in AC 35 ms 6212 KB
1