Submission #00148


ソースコード

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
101
102
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return (n * (n + 1) >> 1); }
inline i64 updiv(i64 a, i64 b) { return (a + b - 1) / b; }
inline i64 sqr(i64 n) { return n * n; }
inline string to_string(char c) { return string(1, c); }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}
inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }
inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
cout << head;
if (sizeof...(tail)) cout << ' ';
print(forward<Tail>(tail)...);
}
template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
static constexpr const char *delim[] = { " ", "" };
for (const auto &e : vec) out << e << delim[&e == &vec.back()];
return out;
}
// }}} End Header
constexpr const char CMAX = '~';
signed main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
var(int, N, M);
vector<string> words(N), revWords(N);
rep(i, N) {
input(words[i]);
revWords[i] = words[i];
reverse(all(revWords[i]));
}
sort(all(words));
sort(all(revWords));
const auto countCandidate = [&words, &revWords](string slate) -> i64 {
if (slate.back() == '*') {
slate.pop_back();
return upper_bound(all(words), slate + CMAX)
- lower_bound(all(words), slate);
} else if (slate.front() == '*') {
reverse(all(slate));
slate.pop_back();
return upper_bound(all(revWords), slate + CMAX)
- lower_bound(all(revWords), slate);
} else {
return upper_bound(all(words), slate) - lower_bound(all(words), slate);
}
};
while(M--) {
var(string, slate);
const int pos = slate.find('?');
if (pos == string::npos) {
print(countCandidate(slate));
} else {
i64 sum = 0;
reps(ch, 'a', 'z') {
slate[pos] = ch;
sum += countCandidate(slate);
}
print(sum);
}
}
return 0;
}

ステータス

項目 データ
問題 0008 - 石版
ユーザー名 poyo
投稿日時 2019-09-10 17:23:13
言語 C++14
状態 Accepted
得点 15
ソースコード長 3344 Byte
最大実行時間 274 ms
最大メモリ使用量 9564 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
00_sample_00.in AC 18 ms 600 KB
1
01_rand_00.in AC 18 ms 556 KB
1
01_rand_01.in AC 26 ms 508 KB
1
01_rand_02.in AC 18 ms 460 KB
1
01_rand_03.in AC 19 ms 540 KB
1
01_rand_04.in AC 19 ms 484 KB
1
01_rand_05.in AC 23 ms 436 KB
1
01_rand_06.in AC 25 ms 512 KB
1
01_rand_07.in AC 22 ms 580 KB
1
01_small_00.in AC 24 ms 516 KB
1
02_large_00.in AC 53 ms 1244 KB
1
02_large_01.in AC 52 ms 1196 KB
1
02_large_02.in AC 124 ms 6912 KB
1
02_large_03.in AC 137 ms 9564 KB
1
03_critical_00.in AC 274 ms 3312 KB
1
03_critical_01.in AC 259 ms 3416 KB
1
77_test_00.in AC 19 ms 1048 KB
1
77_test_01.in AC 22 ms 988 KB
1
77_test_02.in AC 22 ms 920 KB
1
77_test_03.in AC 24 ms 988 KB
1
77_test_04.in AC 19 ms 928 KB
1
77_test_05.in AC 24 ms 1120 KB
1
77_test_06.in AC 18 ms 1056 KB
1
77_test_07.in AC 22 ms 1124 KB
1
77_test_08.in AC 25 ms 1064 KB
1
77_test_09.in AC 17 ms 1004 KB
1
77_test_10.in AC 22 ms 1072 KB
1
77_test_11.in AC 19 ms 1016 KB
1
77_test_12.in AC 16 ms 1088 KB
1
77_test_13.in AC 19 ms 1156 KB
1
77_test_14.in AC 20 ms 1096 KB
1
77_test_15.in AC 29 ms 1168 KB
1
1000_test_00.in AC 19 ms 964 KB
1
1000_test_01.in AC 20 ms 976 KB
1
1000_test_02.in AC 29 ms 984 KB
1
1000_test_03.in AC 26 ms 996 KB
1
1000_test_04.in AC 29 ms 1008 KB
1
1000_test_05.in AC 25 ms 1020 KB
1
1000_test_06.in AC 20 ms 1032 KB
1
1000_test_07.in AC 30 ms 1040 KB
1
1000_test_08.in AC 35 ms 924 KB
1
1000_test_09.in AC 26 ms 1064 KB
1
1000_test_10.in AC 27 ms 1060 KB
1