# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
727115 |
2023-04-20T04:28:33 Z |
stasio6 |
Bowling (BOI15_bow) |
C++14 |
|
947 ms |
8784 KB |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FI first
#define ND second
#define maxeq(x, y) (x) = max((x), (y))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int score[20];
const int maxFrameScore[11] = {0, 10, 30, 60, 90, 120, 150, 180, 210, 240, 300};
ll dp[15][500][12][12];
string game;
bool cmp(int i, char c1, char c2) {
return (game[2*(i-1)] == '?' || game[2*(i-1)] == c1) && (game[2*(i-1)+1] == '?' || game[2*(i-1)+1] == c2);
}
bool scorecmp(int i, int s) {
return score[i] == -1 || score[i] == s;
}
void fun() {
int n;
cin >> n;
cin >> game;
game += "?";
for (int i = 1; i <= n; i++) {
cin >> score[i];
}
for (int i = 0; i < 15; i++)
for (int s = 0; s < 500; s++)
for (int p = 0; p <= 10; p++)
for (int d = 0; d <= 10; d++)
dp[i][s][p][d] = 0;
for (int p = 0; p <= 10; p++) {
for (int d = 0; d <= 10; d++) {
dp[0][0][p][d] = 1;
}
}
for (int i = 1; i < n; i++) {
for (int s = 0; s <= maxFrameScore[i] + 30; s++) {
if (!scorecmp(i, s))
continue;
for (int p = 0; p <= 10; p++) {
for (int d = 0; d <= 10; d++) {
// Strike
if (s >= 10 + d + p && cmp(i, 'x', '-'))
dp[i][s][p][d] += dp[i-1][s - 10 - p - d][10][p];
for (int r1 = 0; r1 < 10; r1++) {
for (int r2 = 0; r2 <= 10 - r1; r2++) {
if (r1+r2 == 10) {
if (!cmp(i, '0'+r1, '/'))
continue;
if (s >= r1 + r2 + p)
dp[i][s][p][d] += dp[i-1][s - r1 - r2 - p][r1][r2];
} else {
if (!cmp(i, '0'+r1, '0'+r2))
continue;
if (s >= r1 + r2)
dp[i][s][p][d] += dp[i-1][s - r1 - r2][r1][r2];
}
}
}
}
}
}
}
// Ostatnia runda
ll ile = 0;
for (int s = 0; s <= 400; s++) {
if (!scorecmp(n, s))
continue;
// 3 striki lub 2 striki cos
for (int t = 0; t <= 10; t++) {
if (!cmp(n, 'x', 'x') || !cmp(n+1, t == 10 ? 'x' : '0'+t, '?'))
continue;
if (s >= 20 + t)
ile += dp[n-1][s-(20+t)][10][10];
}
// strike cos
for (int p = 0; p < 10; p++) {
for (int d = 0; d <= 10 - p; d++) {
if (!cmp(n, 'x', '0'+p) || !cmp(n+1, p+d == 10 ? '/' : '0'+d, '?'))
continue;
if (s >= 10 + p + d)
ile += dp[n-1][s-(10 + p + d)][10][p];
}
}
// spare cos
for (int p = 0; p < 10; p++) {
for (int d = 0; d <= 10; d++) {
if (!cmp(n, '0'+p, '/') || !cmp(n+1, d == 10 ? 'x' : '0'+d, '?'))
continue;
if (s >= 10 + d)
ile += dp[n-1][s-(10 + d)][p][10-p];
}
}
// cos
for (int p = 0; p < 10; p++) {
for (int d = 0; d < 10-p; d++) {
if (!cmp(n, '0'+p, '0'+d) || !cmp(n+1, '-', '?'))
continue;
if (s >= p+d)
ile += dp[n-1][s-(p+d)][p][d];
}
}
}
cout << ile << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) fun();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
8760 KB |
Output is correct |
2 |
Correct |
112 ms |
8760 KB |
Output is correct |
3 |
Correct |
30 ms |
8784 KB |
Output is correct |
4 |
Correct |
29 ms |
8660 KB |
Output is correct |
5 |
Correct |
29 ms |
8660 KB |
Output is correct |
6 |
Correct |
30 ms |
8648 KB |
Output is correct |
7 |
Correct |
321 ms |
8660 KB |
Output is correct |
8 |
Correct |
270 ms |
8780 KB |
Output is correct |
9 |
Correct |
204 ms |
8764 KB |
Output is correct |
10 |
Correct |
270 ms |
8760 KB |
Output is correct |
11 |
Correct |
363 ms |
8756 KB |
Output is correct |
12 |
Correct |
58 ms |
8760 KB |
Output is correct |
13 |
Correct |
16 ms |
8780 KB |
Output is correct |
14 |
Correct |
57 ms |
8660 KB |
Output is correct |
15 |
Correct |
19 ms |
8780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
222 ms |
8760 KB |
Output is correct |
2 |
Correct |
177 ms |
8756 KB |
Output is correct |
3 |
Correct |
165 ms |
8756 KB |
Output is correct |
4 |
Correct |
154 ms |
8780 KB |
Output is correct |
5 |
Correct |
176 ms |
8756 KB |
Output is correct |
6 |
Correct |
310 ms |
8760 KB |
Output is correct |
7 |
Correct |
331 ms |
8760 KB |
Output is correct |
8 |
Correct |
345 ms |
8760 KB |
Output is correct |
9 |
Correct |
286 ms |
8780 KB |
Output is correct |
10 |
Correct |
464 ms |
8648 KB |
Output is correct |
11 |
Correct |
487 ms |
8756 KB |
Output is correct |
12 |
Correct |
468 ms |
8780 KB |
Output is correct |
13 |
Correct |
445 ms |
8760 KB |
Output is correct |
14 |
Correct |
272 ms |
8756 KB |
Output is correct |
15 |
Correct |
285 ms |
8756 KB |
Output is correct |
16 |
Correct |
258 ms |
8660 KB |
Output is correct |
17 |
Correct |
242 ms |
8764 KB |
Output is correct |
18 |
Correct |
627 ms |
8756 KB |
Output is correct |
19 |
Correct |
630 ms |
8756 KB |
Output is correct |
20 |
Correct |
631 ms |
8756 KB |
Output is correct |
21 |
Correct |
634 ms |
8760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
8764 KB |
Output is correct |
2 |
Correct |
70 ms |
8656 KB |
Output is correct |
3 |
Correct |
74 ms |
8764 KB |
Output is correct |
4 |
Correct |
90 ms |
8660 KB |
Output is correct |
5 |
Correct |
110 ms |
8760 KB |
Output is correct |
6 |
Correct |
105 ms |
8760 KB |
Output is correct |
7 |
Correct |
87 ms |
8660 KB |
Output is correct |
8 |
Correct |
118 ms |
8660 KB |
Output is correct |
9 |
Correct |
94 ms |
8760 KB |
Output is correct |
10 |
Correct |
101 ms |
8760 KB |
Output is correct |
11 |
Correct |
64 ms |
8660 KB |
Output is correct |
12 |
Correct |
74 ms |
8756 KB |
Output is correct |
13 |
Correct |
61 ms |
8764 KB |
Output is correct |
14 |
Correct |
94 ms |
8660 KB |
Output is correct |
15 |
Correct |
131 ms |
8780 KB |
Output is correct |
16 |
Correct |
142 ms |
8760 KB |
Output is correct |
17 |
Correct |
154 ms |
8756 KB |
Output is correct |
18 |
Correct |
185 ms |
8660 KB |
Output is correct |
19 |
Correct |
208 ms |
8772 KB |
Output is correct |
20 |
Correct |
221 ms |
8764 KB |
Output is correct |
21 |
Correct |
234 ms |
8764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
322 ms |
8764 KB |
Output is correct |
2 |
Correct |
221 ms |
8660 KB |
Output is correct |
3 |
Correct |
272 ms |
8752 KB |
Output is correct |
4 |
Correct |
221 ms |
8780 KB |
Output is correct |
5 |
Correct |
226 ms |
8760 KB |
Output is correct |
6 |
Correct |
204 ms |
8764 KB |
Output is correct |
7 |
Correct |
190 ms |
8660 KB |
Output is correct |
8 |
Correct |
187 ms |
8756 KB |
Output is correct |
9 |
Correct |
207 ms |
8760 KB |
Output is correct |
10 |
Correct |
428 ms |
8772 KB |
Output is correct |
11 |
Correct |
386 ms |
8764 KB |
Output is correct |
12 |
Correct |
377 ms |
8760 KB |
Output is correct |
13 |
Correct |
348 ms |
8660 KB |
Output is correct |
14 |
Correct |
472 ms |
8772 KB |
Output is correct |
15 |
Correct |
433 ms |
8760 KB |
Output is correct |
16 |
Correct |
401 ms |
8780 KB |
Output is correct |
17 |
Correct |
445 ms |
8756 KB |
Output is correct |
18 |
Correct |
368 ms |
8768 KB |
Output is correct |
19 |
Correct |
373 ms |
8756 KB |
Output is correct |
20 |
Correct |
392 ms |
8760 KB |
Output is correct |
21 |
Correct |
370 ms |
8764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
8760 KB |
Output is correct |
2 |
Correct |
112 ms |
8760 KB |
Output is correct |
3 |
Correct |
30 ms |
8784 KB |
Output is correct |
4 |
Correct |
29 ms |
8660 KB |
Output is correct |
5 |
Correct |
29 ms |
8660 KB |
Output is correct |
6 |
Correct |
30 ms |
8648 KB |
Output is correct |
7 |
Correct |
321 ms |
8660 KB |
Output is correct |
8 |
Correct |
270 ms |
8780 KB |
Output is correct |
9 |
Correct |
204 ms |
8764 KB |
Output is correct |
10 |
Correct |
270 ms |
8760 KB |
Output is correct |
11 |
Correct |
363 ms |
8756 KB |
Output is correct |
12 |
Correct |
58 ms |
8760 KB |
Output is correct |
13 |
Correct |
16 ms |
8780 KB |
Output is correct |
14 |
Correct |
57 ms |
8660 KB |
Output is correct |
15 |
Correct |
19 ms |
8780 KB |
Output is correct |
16 |
Correct |
222 ms |
8760 KB |
Output is correct |
17 |
Correct |
177 ms |
8756 KB |
Output is correct |
18 |
Correct |
165 ms |
8756 KB |
Output is correct |
19 |
Correct |
154 ms |
8780 KB |
Output is correct |
20 |
Correct |
176 ms |
8756 KB |
Output is correct |
21 |
Correct |
310 ms |
8760 KB |
Output is correct |
22 |
Correct |
331 ms |
8760 KB |
Output is correct |
23 |
Correct |
345 ms |
8760 KB |
Output is correct |
24 |
Correct |
286 ms |
8780 KB |
Output is correct |
25 |
Correct |
464 ms |
8648 KB |
Output is correct |
26 |
Correct |
487 ms |
8756 KB |
Output is correct |
27 |
Correct |
468 ms |
8780 KB |
Output is correct |
28 |
Correct |
445 ms |
8760 KB |
Output is correct |
29 |
Correct |
272 ms |
8756 KB |
Output is correct |
30 |
Correct |
285 ms |
8756 KB |
Output is correct |
31 |
Correct |
258 ms |
8660 KB |
Output is correct |
32 |
Correct |
242 ms |
8764 KB |
Output is correct |
33 |
Correct |
627 ms |
8756 KB |
Output is correct |
34 |
Correct |
630 ms |
8756 KB |
Output is correct |
35 |
Correct |
631 ms |
8756 KB |
Output is correct |
36 |
Correct |
634 ms |
8760 KB |
Output is correct |
37 |
Correct |
110 ms |
8764 KB |
Output is correct |
38 |
Correct |
70 ms |
8656 KB |
Output is correct |
39 |
Correct |
74 ms |
8764 KB |
Output is correct |
40 |
Correct |
90 ms |
8660 KB |
Output is correct |
41 |
Correct |
110 ms |
8760 KB |
Output is correct |
42 |
Correct |
105 ms |
8760 KB |
Output is correct |
43 |
Correct |
87 ms |
8660 KB |
Output is correct |
44 |
Correct |
118 ms |
8660 KB |
Output is correct |
45 |
Correct |
94 ms |
8760 KB |
Output is correct |
46 |
Correct |
101 ms |
8760 KB |
Output is correct |
47 |
Correct |
64 ms |
8660 KB |
Output is correct |
48 |
Correct |
74 ms |
8756 KB |
Output is correct |
49 |
Correct |
61 ms |
8764 KB |
Output is correct |
50 |
Correct |
94 ms |
8660 KB |
Output is correct |
51 |
Correct |
131 ms |
8780 KB |
Output is correct |
52 |
Correct |
142 ms |
8760 KB |
Output is correct |
53 |
Correct |
154 ms |
8756 KB |
Output is correct |
54 |
Correct |
185 ms |
8660 KB |
Output is correct |
55 |
Correct |
208 ms |
8772 KB |
Output is correct |
56 |
Correct |
221 ms |
8764 KB |
Output is correct |
57 |
Correct |
234 ms |
8764 KB |
Output is correct |
58 |
Correct |
322 ms |
8764 KB |
Output is correct |
59 |
Correct |
221 ms |
8660 KB |
Output is correct |
60 |
Correct |
272 ms |
8752 KB |
Output is correct |
61 |
Correct |
221 ms |
8780 KB |
Output is correct |
62 |
Correct |
226 ms |
8760 KB |
Output is correct |
63 |
Correct |
204 ms |
8764 KB |
Output is correct |
64 |
Correct |
190 ms |
8660 KB |
Output is correct |
65 |
Correct |
187 ms |
8756 KB |
Output is correct |
66 |
Correct |
207 ms |
8760 KB |
Output is correct |
67 |
Correct |
428 ms |
8772 KB |
Output is correct |
68 |
Correct |
386 ms |
8764 KB |
Output is correct |
69 |
Correct |
377 ms |
8760 KB |
Output is correct |
70 |
Correct |
348 ms |
8660 KB |
Output is correct |
71 |
Correct |
472 ms |
8772 KB |
Output is correct |
72 |
Correct |
433 ms |
8760 KB |
Output is correct |
73 |
Correct |
401 ms |
8780 KB |
Output is correct |
74 |
Correct |
445 ms |
8756 KB |
Output is correct |
75 |
Correct |
368 ms |
8768 KB |
Output is correct |
76 |
Correct |
373 ms |
8756 KB |
Output is correct |
77 |
Correct |
392 ms |
8760 KB |
Output is correct |
78 |
Correct |
370 ms |
8764 KB |
Output is correct |
79 |
Correct |
254 ms |
8660 KB |
Output is correct |
80 |
Correct |
214 ms |
8760 KB |
Output is correct |
81 |
Correct |
182 ms |
8660 KB |
Output is correct |
82 |
Correct |
193 ms |
8780 KB |
Output is correct |
83 |
Correct |
148 ms |
8660 KB |
Output is correct |
84 |
Correct |
87 ms |
8660 KB |
Output is correct |
85 |
Correct |
97 ms |
8768 KB |
Output is correct |
86 |
Correct |
72 ms |
8660 KB |
Output is correct |
87 |
Correct |
81 ms |
8660 KB |
Output is correct |
88 |
Correct |
383 ms |
8660 KB |
Output is correct |
89 |
Correct |
467 ms |
8660 KB |
Output is correct |
90 |
Correct |
483 ms |
8764 KB |
Output is correct |
91 |
Correct |
480 ms |
8756 KB |
Output is correct |
92 |
Correct |
476 ms |
8756 KB |
Output is correct |
93 |
Correct |
926 ms |
8756 KB |
Output is correct |
94 |
Correct |
947 ms |
8756 KB |
Output is correct |
95 |
Correct |
926 ms |
8760 KB |
Output is correct |
96 |
Correct |
918 ms |
8760 KB |
Output is correct |
97 |
Correct |
908 ms |
8760 KB |
Output is correct |
98 |
Correct |
915 ms |
8776 KB |
Output is correct |
99 |
Correct |
934 ms |
8760 KB |
Output is correct |
100 |
Correct |
928 ms |
8756 KB |
Output is correct |