#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;
long long dp[12][12][12][360];
vector<tuple<string, int, int, int>> bnormal, blast;
void init() {
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= 10 - i; j++) {
string V = "";
if (i == 10) V = "x-";
else if (i + j == 10) V = to_string(i) + "/";
else V = to_string(i) + to_string(j);
bnormal.push_back(make_tuple(V, i, j, 0));
}
}
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k <= 10; k++) {
if (i + j > 10 && i != 10) continue;
if (i == 10) {
if (j + k > 10 && j != 10) continue;
}
if (i + j < 10 && k >= 1) continue;
string V = "";
if (i == 10 && j == 10 && k == 10) V = "xxx";
else if (i == 10 && j == 10) V = "xx" + to_string(k);
else if (i == 10 && j + k == 10) V = "x" + to_string(j) + "/";
else if (i == 10) V = "x" + to_string(j) + to_string(k);
else if (i + j == 10 && k == 10) V += to_string(i) + "/x";
else if (i + j == 10) V += to_string(i) + "/" + to_string(k);
else V += to_string(i) + to_string(j) + "-";
blast.push_back(make_tuple(V, i, j, k));
}
}
}
sort(bnormal.begin(), bnormal.end()); bnormal.erase(unique(bnormal.begin(), bnormal.end()), bnormal.end());
sort(blast.begin(), blast.end()); blast.erase(unique(blast.begin(), blast.end()), blast.end());
return;
}
long long solve(string S, vector<int>vec) {
for (int i = 0; i < 12 * 12; i++) {
for (int j = 0; j < 12 * 360; j++) dp[i / 12][i % 12][j / 360][j % 360] = 0;
}
for (int i = 0; i < blast.size(); i++) {
bool flag = true;
for (int j = 0; j < 3; j++) { if (S[j + (int)(vec.size() - 1) * 2] != '?' && S[j + (int)(vec.size() - 1) * 2] != get<0>(blast[i])[j]) flag = false; }
if (flag == true) {
for (int j = 0; j <= 330; j++) {
if (vec[vec.size() - 1] != -1 && vec[vec.size() - 1] != j) continue;
int G1 = get<1>(blast[i]) + get<2>(blast[i]) + get<3>(blast[i]);
if (j >= G1) {
dp[vec.size() - 1][get<1>(blast[i])][get<2>(blast[i])][j - G1] += 1;
}
}
}
}
for (int i = (int)vec.size() - 2; i >= 0; i--) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k <= 10; k++) {
for (int l = 0; l <= 330; l++) {
if (vec[i] != -1 && l != vec[i]) dp[i + 1][j][k][l] = 0;
if (dp[i + 1][j][k][l] == 0) continue;
for (int m = 0; m < bnormal.size(); m++) {
bool flag = true;
for (int n = 0; n < 2; n++) { if (S[i * 2 + n] != '?' && S[i * 2 + n] != get<0>(bnormal[m])[n]) flag = false; }
if (flag == true) {
int G1 = get<1>(bnormal[m]) + get<2>(bnormal[m]);
int G2 = 0;
if (get<0>(bnormal[m])[1] == '/') G2 = j; // 1 回前
if (get<0>(bnormal[m])[0] == 'x') G2 = j + k; // 2 回前
int v1 = get<1>(bnormal[m]), v2 = get<2>(bnormal[m]);
if (v1 == 10) { v2 = j; }
if (l >= G1 + G2) {
dp[i][v1][v2][l - (G1 + G2)] += dp[i + 1][j][k][l];
}
}
}
}
}
}
}
long long sum = 0;
for (int i = 0; i <= 10; i++) { for (int j = 0; j <= 10; j++) sum += dp[0][i][j][0]; }
return sum;
}
int main() {
init();
int Q, N; string str;
cin >> Q;
for (int i = 1; i <= Q; i++) {
cin >> N >> str; vector<int>A(N, 0);
for (int j = 0; j < N; j++) cin >> A[j];
cout << solve(str, A) << endl;
}
return 0;
}
Compilation message
bow.cpp: In function 'long long int solve(std::__cxx11::string, std::vector<int>)':
bow.cpp:51:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < blast.size(); i++) {
~~^~~~~~~~~~~~~~
bow.cpp:71:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int m = 0; m < bnormal.size(); m++) {
~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
5248 KB |
Output is correct |
2 |
Correct |
42 ms |
5248 KB |
Output is correct |
3 |
Correct |
39 ms |
5168 KB |
Output is correct |
4 |
Correct |
42 ms |
5248 KB |
Output is correct |
5 |
Correct |
41 ms |
5248 KB |
Output is correct |
6 |
Correct |
42 ms |
5248 KB |
Output is correct |
7 |
Correct |
78 ms |
5248 KB |
Output is correct |
8 |
Correct |
68 ms |
5248 KB |
Output is correct |
9 |
Correct |
62 ms |
5248 KB |
Output is correct |
10 |
Correct |
65 ms |
5248 KB |
Output is correct |
11 |
Correct |
48 ms |
5212 KB |
Output is correct |
12 |
Correct |
38 ms |
5248 KB |
Output is correct |
13 |
Correct |
13 ms |
5248 KB |
Output is correct |
14 |
Correct |
42 ms |
5248 KB |
Output is correct |
15 |
Correct |
13 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
5248 KB |
Output is correct |
2 |
Correct |
70 ms |
5248 KB |
Output is correct |
3 |
Correct |
69 ms |
5220 KB |
Output is correct |
4 |
Correct |
52 ms |
5248 KB |
Output is correct |
5 |
Correct |
69 ms |
5248 KB |
Output is correct |
6 |
Correct |
56 ms |
5248 KB |
Output is correct |
7 |
Correct |
75 ms |
5248 KB |
Output is correct |
8 |
Correct |
66 ms |
5248 KB |
Output is correct |
9 |
Correct |
56 ms |
5248 KB |
Output is correct |
10 |
Correct |
118 ms |
5248 KB |
Output is correct |
11 |
Correct |
122 ms |
5248 KB |
Output is correct |
12 |
Correct |
153 ms |
5304 KB |
Output is correct |
13 |
Correct |
141 ms |
5248 KB |
Output is correct |
14 |
Correct |
74 ms |
5360 KB |
Output is correct |
15 |
Correct |
73 ms |
5248 KB |
Output is correct |
16 |
Correct |
60 ms |
5248 KB |
Output is correct |
17 |
Correct |
68 ms |
5248 KB |
Output is correct |
18 |
Correct |
181 ms |
5268 KB |
Output is correct |
19 |
Correct |
190 ms |
5248 KB |
Output is correct |
20 |
Correct |
182 ms |
5248 KB |
Output is correct |
21 |
Correct |
209 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
5244 KB |
Output is correct |
2 |
Correct |
43 ms |
5248 KB |
Output is correct |
3 |
Correct |
43 ms |
5248 KB |
Output is correct |
4 |
Correct |
44 ms |
5248 KB |
Output is correct |
5 |
Correct |
40 ms |
5248 KB |
Output is correct |
6 |
Correct |
44 ms |
5248 KB |
Output is correct |
7 |
Correct |
45 ms |
5292 KB |
Output is correct |
8 |
Correct |
46 ms |
5248 KB |
Output is correct |
9 |
Correct |
46 ms |
5248 KB |
Output is correct |
10 |
Correct |
47 ms |
5220 KB |
Output is correct |
11 |
Correct |
47 ms |
5220 KB |
Output is correct |
12 |
Correct |
47 ms |
5248 KB |
Output is correct |
13 |
Correct |
48 ms |
5248 KB |
Output is correct |
14 |
Correct |
47 ms |
5248 KB |
Output is correct |
15 |
Correct |
48 ms |
5248 KB |
Output is correct |
16 |
Correct |
47 ms |
5248 KB |
Output is correct |
17 |
Correct |
52 ms |
5248 KB |
Output is correct |
18 |
Correct |
46 ms |
5248 KB |
Output is correct |
19 |
Correct |
45 ms |
5248 KB |
Output is correct |
20 |
Correct |
46 ms |
5168 KB |
Output is correct |
21 |
Correct |
47 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
5248 KB |
Output is correct |
2 |
Correct |
134 ms |
5248 KB |
Output is correct |
3 |
Correct |
186 ms |
5248 KB |
Output is correct |
4 |
Correct |
167 ms |
5248 KB |
Output is correct |
5 |
Correct |
134 ms |
5248 KB |
Output is correct |
6 |
Correct |
111 ms |
5248 KB |
Output is correct |
7 |
Correct |
138 ms |
5248 KB |
Output is correct |
8 |
Correct |
114 ms |
5248 KB |
Output is correct |
9 |
Correct |
130 ms |
5248 KB |
Output is correct |
10 |
Correct |
498 ms |
5248 KB |
Output is correct |
11 |
Correct |
462 ms |
5276 KB |
Output is correct |
12 |
Correct |
452 ms |
5292 KB |
Output is correct |
13 |
Correct |
487 ms |
5368 KB |
Output is correct |
14 |
Correct |
125 ms |
5248 KB |
Output is correct |
15 |
Correct |
98 ms |
5248 KB |
Output is correct |
16 |
Correct |
114 ms |
5248 KB |
Output is correct |
17 |
Correct |
99 ms |
5240 KB |
Output is correct |
18 |
Correct |
49 ms |
5248 KB |
Output is correct |
19 |
Correct |
63 ms |
5248 KB |
Output is correct |
20 |
Correct |
68 ms |
5248 KB |
Output is correct |
21 |
Correct |
55 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
5248 KB |
Output is correct |
2 |
Correct |
42 ms |
5248 KB |
Output is correct |
3 |
Correct |
39 ms |
5168 KB |
Output is correct |
4 |
Correct |
42 ms |
5248 KB |
Output is correct |
5 |
Correct |
41 ms |
5248 KB |
Output is correct |
6 |
Correct |
42 ms |
5248 KB |
Output is correct |
7 |
Correct |
78 ms |
5248 KB |
Output is correct |
8 |
Correct |
68 ms |
5248 KB |
Output is correct |
9 |
Correct |
62 ms |
5248 KB |
Output is correct |
10 |
Correct |
65 ms |
5248 KB |
Output is correct |
11 |
Correct |
48 ms |
5212 KB |
Output is correct |
12 |
Correct |
38 ms |
5248 KB |
Output is correct |
13 |
Correct |
13 ms |
5248 KB |
Output is correct |
14 |
Correct |
42 ms |
5248 KB |
Output is correct |
15 |
Correct |
13 ms |
5248 KB |
Output is correct |
16 |
Correct |
36 ms |
5248 KB |
Output is correct |
17 |
Correct |
70 ms |
5248 KB |
Output is correct |
18 |
Correct |
69 ms |
5220 KB |
Output is correct |
19 |
Correct |
52 ms |
5248 KB |
Output is correct |
20 |
Correct |
69 ms |
5248 KB |
Output is correct |
21 |
Correct |
56 ms |
5248 KB |
Output is correct |
22 |
Correct |
75 ms |
5248 KB |
Output is correct |
23 |
Correct |
66 ms |
5248 KB |
Output is correct |
24 |
Correct |
56 ms |
5248 KB |
Output is correct |
25 |
Correct |
118 ms |
5248 KB |
Output is correct |
26 |
Correct |
122 ms |
5248 KB |
Output is correct |
27 |
Correct |
153 ms |
5304 KB |
Output is correct |
28 |
Correct |
141 ms |
5248 KB |
Output is correct |
29 |
Correct |
74 ms |
5360 KB |
Output is correct |
30 |
Correct |
73 ms |
5248 KB |
Output is correct |
31 |
Correct |
60 ms |
5248 KB |
Output is correct |
32 |
Correct |
68 ms |
5248 KB |
Output is correct |
33 |
Correct |
181 ms |
5268 KB |
Output is correct |
34 |
Correct |
190 ms |
5248 KB |
Output is correct |
35 |
Correct |
182 ms |
5248 KB |
Output is correct |
36 |
Correct |
209 ms |
5248 KB |
Output is correct |
37 |
Correct |
20 ms |
5244 KB |
Output is correct |
38 |
Correct |
43 ms |
5248 KB |
Output is correct |
39 |
Correct |
43 ms |
5248 KB |
Output is correct |
40 |
Correct |
44 ms |
5248 KB |
Output is correct |
41 |
Correct |
40 ms |
5248 KB |
Output is correct |
42 |
Correct |
44 ms |
5248 KB |
Output is correct |
43 |
Correct |
45 ms |
5292 KB |
Output is correct |
44 |
Correct |
46 ms |
5248 KB |
Output is correct |
45 |
Correct |
46 ms |
5248 KB |
Output is correct |
46 |
Correct |
47 ms |
5220 KB |
Output is correct |
47 |
Correct |
47 ms |
5220 KB |
Output is correct |
48 |
Correct |
47 ms |
5248 KB |
Output is correct |
49 |
Correct |
48 ms |
5248 KB |
Output is correct |
50 |
Correct |
47 ms |
5248 KB |
Output is correct |
51 |
Correct |
48 ms |
5248 KB |
Output is correct |
52 |
Correct |
47 ms |
5248 KB |
Output is correct |
53 |
Correct |
52 ms |
5248 KB |
Output is correct |
54 |
Correct |
46 ms |
5248 KB |
Output is correct |
55 |
Correct |
45 ms |
5248 KB |
Output is correct |
56 |
Correct |
46 ms |
5168 KB |
Output is correct |
57 |
Correct |
47 ms |
5248 KB |
Output is correct |
58 |
Correct |
175 ms |
5248 KB |
Output is correct |
59 |
Correct |
134 ms |
5248 KB |
Output is correct |
60 |
Correct |
186 ms |
5248 KB |
Output is correct |
61 |
Correct |
167 ms |
5248 KB |
Output is correct |
62 |
Correct |
134 ms |
5248 KB |
Output is correct |
63 |
Correct |
111 ms |
5248 KB |
Output is correct |
64 |
Correct |
138 ms |
5248 KB |
Output is correct |
65 |
Correct |
114 ms |
5248 KB |
Output is correct |
66 |
Correct |
130 ms |
5248 KB |
Output is correct |
67 |
Correct |
498 ms |
5248 KB |
Output is correct |
68 |
Correct |
462 ms |
5276 KB |
Output is correct |
69 |
Correct |
452 ms |
5292 KB |
Output is correct |
70 |
Correct |
487 ms |
5368 KB |
Output is correct |
71 |
Correct |
125 ms |
5248 KB |
Output is correct |
72 |
Correct |
98 ms |
5248 KB |
Output is correct |
73 |
Correct |
114 ms |
5248 KB |
Output is correct |
74 |
Correct |
99 ms |
5240 KB |
Output is correct |
75 |
Correct |
49 ms |
5248 KB |
Output is correct |
76 |
Correct |
63 ms |
5248 KB |
Output is correct |
77 |
Correct |
68 ms |
5248 KB |
Output is correct |
78 |
Correct |
55 ms |
5248 KB |
Output is correct |
79 |
Correct |
204 ms |
5300 KB |
Output is correct |
80 |
Correct |
98 ms |
5248 KB |
Output is correct |
81 |
Correct |
97 ms |
5248 KB |
Output is correct |
82 |
Correct |
63 ms |
5376 KB |
Output is correct |
83 |
Correct |
68 ms |
5248 KB |
Output is correct |
84 |
Correct |
48 ms |
5248 KB |
Output is correct |
85 |
Correct |
54 ms |
5248 KB |
Output is correct |
86 |
Correct |
45 ms |
5248 KB |
Output is correct |
87 |
Correct |
49 ms |
5248 KB |
Output is correct |
88 |
Correct |
70 ms |
5248 KB |
Output is correct |
89 |
Correct |
128 ms |
5376 KB |
Output is correct |
90 |
Correct |
120 ms |
5248 KB |
Output is correct |
91 |
Correct |
138 ms |
5248 KB |
Output is correct |
92 |
Correct |
57 ms |
5248 KB |
Output is correct |
93 |
Correct |
71 ms |
5248 KB |
Output is correct |
94 |
Correct |
145 ms |
5248 KB |
Output is correct |
95 |
Correct |
231 ms |
5248 KB |
Output is correct |
96 |
Correct |
309 ms |
5248 KB |
Output is correct |
97 |
Correct |
566 ms |
5248 KB |
Output is correct |
98 |
Correct |
575 ms |
5248 KB |
Output is correct |
99 |
Correct |
587 ms |
5248 KB |
Output is correct |
100 |
Correct |
582 ms |
5256 KB |
Output is correct |