Submission #793649

# Submission time Handle Problem Language Result Execution time Memory
793649 2023-07-26T05:05:08 Z rk42745417 Bowling (BOI15_bow) C++17
100 / 100
282 ms 4284 KB
#include <bits/stdc++.h>
using namespace std;
 
#define EMiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(2e18) + ll(1e15);
const double EPS = 1e-8;
static auto LamyIsCute = []() {
	EMiliaMyWife
	return 48763;
}();
 
const int N = 350;
ll dp[10][N][12][12]; // (current score, score needed next shot, score needed two next shot)
 
signed main() {
	int tc;
	cin >> tc;
	while(tc--) {
		memset(dp, 0, sizeof dp);
		dp[0][0][11][11] = 1;
		string s;
		int n;
		cin >> n >> s;
		vector<int> arr(n);
		for(int i = 0; i < n; i++)
			cin >> arr[i];
 
		auto mat = [&](const string &a, string b) {
			for(int i = 0; i < a.size(); i++)
				if(a[i] != '?' && a[i] != b[i])
					return false;
			return true;
		};
 
		for(int i = 0; i < n - 1; i++) {
			const int sc = arr[i];
			const string cur_round = string(1, s[2 * i]) + s[2 * i + 1];
			for(int j = 0; j < N; j++) {
				for(int k = 0; k <= 11; k++) {
					for(int w = 0; w <= 11; w++) {
						if(dp[i][j][k][w] == 0)
							continue;
						const ll cur = dp[i][j][k][w];
						for(int a = 0; a <= 10; a++) {
							if(k != 11 && k != a)
								continue;
							if(a == 10) {
								if(!mat(cur_round, string("x-")))
									continue;
								for(int t = 0; t <= 10; t++)
									for(int r = 0; r <= 10; r++)
										if((sc == -1 || sc == j + 10 + t + r) && (w == 11 || t == w))
											dp[i + 1][j + 10 + t + r][t][r] += cur;
								continue;
							}
							string x(1, a + '0');
							for(int b = 0; a + b <= 10; b++) {
								if(w != 11 && w != b)
									continue;
								if(a + b == 10) {
									if(!mat(cur_round, x + "/"))
										continue;
									for(int t = 0; t <= 10; t++)
										if(sc == -1 || sc == j + 10 + t)
											dp[i + 1][j + 10 + t][t][11] += cur;
									continue;
								}
								if(!mat(cur_round, x + char(b + '0')))
									continue;
								if(sc == -1 || j + a + b == sc)
									dp[i + 1][j + a + b][11][11] += cur;
							}
						}
					}
				}
			}
		}
		ll ans = 0;
		const string cur_round = s.substr(s.size() - 3, 3);
		const int sc = arr.back();
		for(int i = 0; i < N; i++) {
			for(int j = 0; j <= 11; j++) {
				for(int k = 0; k <= 11; k++) {
					const ll cur = dp[n - 1][i][j][k];
					if(cur == 0)
						continue;
					for(int a = 0; a <= 10; a++) {
						if(j != 11 && j != a)
							continue;
						string t;
						if(a == 10)
							t += 'x';
						else
							t += char(a + '0');
						for(int b = 0; b <= 10; b++) {
							if(k != 11 && k != b)
								continue;
							if(a != 10 && b + a > 10)
								continue;
							if(a + b < 10) {
								if(!mat(cur_round, t + char(b + '0') + "-"))
									continue;
								if((sc == -1 || a + b + i == sc))
									ans += cur;
								continue;
							}
							if(a == 10) {
								if(b == 10)
									t.push_back('x');
								else
									t.push_back(b + '0');
							}
							else
								t.push_back('/');
							for(int c = 0; c <= 10; c++) {
								if(a == 10 && b != 10 && b + c > 10)
									continue;
								if(a == 10 && b != 10 && b + c == 10)
									t.push_back('/');
								else if(c == 10)
									t.push_back('x');
								else
									t.push_back(c + '0');
								if(mat(cur_round, t) && (sc == -1 || sc == i + a + b + c))
									ans += cur;
								t.pop_back();
							}
							t.pop_back();
						}
					}
				}
			}
		}
		cout << ans << '\n';
	}
}

Compilation message

bow.cpp: In lambda function:
bow.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for(int i = 0; i < a.size(); i++)
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4272 KB Output is correct
2 Correct 11 ms 4272 KB Output is correct
3 Correct 12 ms 4272 KB Output is correct
4 Correct 12 ms 4172 KB Output is correct
5 Correct 11 ms 4268 KB Output is correct
6 Correct 12 ms 4180 KB Output is correct
7 Correct 19 ms 4268 KB Output is correct
8 Correct 17 ms 4272 KB Output is correct
9 Correct 21 ms 4180 KB Output is correct
10 Correct 17 ms 4264 KB Output is correct
11 Correct 18 ms 4280 KB Output is correct
12 Correct 8 ms 4180 KB Output is correct
13 Correct 3 ms 4180 KB Output is correct
14 Correct 8 ms 4180 KB Output is correct
15 Correct 3 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 4180 KB Output is correct
2 Correct 16 ms 4272 KB Output is correct
3 Correct 19 ms 4180 KB Output is correct
4 Correct 14 ms 4272 KB Output is correct
5 Correct 21 ms 4176 KB Output is correct
6 Correct 19 ms 4180 KB Output is correct
7 Correct 21 ms 4272 KB Output is correct
8 Correct 22 ms 4176 KB Output is correct
9 Correct 21 ms 4248 KB Output is correct
10 Correct 31 ms 4180 KB Output is correct
11 Correct 38 ms 4252 KB Output is correct
12 Correct 35 ms 4180 KB Output is correct
13 Correct 34 ms 4180 KB Output is correct
14 Correct 19 ms 4276 KB Output is correct
15 Correct 19 ms 4284 KB Output is correct
16 Correct 18 ms 4180 KB Output is correct
17 Correct 20 ms 4272 KB Output is correct
18 Correct 68 ms 4180 KB Output is correct
19 Correct 55 ms 4180 KB Output is correct
20 Correct 54 ms 4256 KB Output is correct
21 Correct 61 ms 4252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 4176 KB Output is correct
2 Correct 13 ms 4276 KB Output is correct
3 Correct 11 ms 4168 KB Output is correct
4 Correct 11 ms 4180 KB Output is correct
5 Correct 11 ms 4180 KB Output is correct
6 Correct 15 ms 4176 KB Output is correct
7 Correct 15 ms 4180 KB Output is correct
8 Correct 20 ms 4180 KB Output is correct
9 Correct 16 ms 4276 KB Output is correct
10 Correct 25 ms 4176 KB Output is correct
11 Correct 16 ms 4276 KB Output is correct
12 Correct 17 ms 4276 KB Output is correct
13 Correct 17 ms 4180 KB Output is correct
14 Correct 16 ms 4180 KB Output is correct
15 Correct 22 ms 4180 KB Output is correct
16 Correct 19 ms 4252 KB Output is correct
17 Correct 17 ms 4276 KB Output is correct
18 Correct 19 ms 4180 KB Output is correct
19 Correct 18 ms 4180 KB Output is correct
20 Correct 17 ms 4180 KB Output is correct
21 Correct 16 ms 4276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 4180 KB Output is correct
2 Correct 18 ms 4180 KB Output is correct
3 Correct 26 ms 4180 KB Output is correct
4 Correct 25 ms 4180 KB Output is correct
5 Correct 19 ms 4276 KB Output is correct
6 Correct 21 ms 4244 KB Output is correct
7 Correct 17 ms 4272 KB Output is correct
8 Correct 16 ms 4276 KB Output is correct
9 Correct 19 ms 4180 KB Output is correct
10 Correct 70 ms 4248 KB Output is correct
11 Correct 68 ms 4248 KB Output is correct
12 Correct 64 ms 4252 KB Output is correct
13 Correct 73 ms 4248 KB Output is correct
14 Correct 29 ms 4168 KB Output is correct
15 Correct 28 ms 4272 KB Output is correct
16 Correct 30 ms 4180 KB Output is correct
17 Correct 27 ms 4276 KB Output is correct
18 Correct 19 ms 4276 KB Output is correct
19 Correct 20 ms 4280 KB Output is correct
20 Correct 20 ms 4180 KB Output is correct
21 Correct 20 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4272 KB Output is correct
2 Correct 11 ms 4272 KB Output is correct
3 Correct 12 ms 4272 KB Output is correct
4 Correct 12 ms 4172 KB Output is correct
5 Correct 11 ms 4268 KB Output is correct
6 Correct 12 ms 4180 KB Output is correct
7 Correct 19 ms 4268 KB Output is correct
8 Correct 17 ms 4272 KB Output is correct
9 Correct 21 ms 4180 KB Output is correct
10 Correct 17 ms 4264 KB Output is correct
11 Correct 18 ms 4280 KB Output is correct
12 Correct 8 ms 4180 KB Output is correct
13 Correct 3 ms 4180 KB Output is correct
14 Correct 8 ms 4180 KB Output is correct
15 Correct 3 ms 4180 KB Output is correct
16 Correct 19 ms 4180 KB Output is correct
17 Correct 16 ms 4272 KB Output is correct
18 Correct 19 ms 4180 KB Output is correct
19 Correct 14 ms 4272 KB Output is correct
20 Correct 21 ms 4176 KB Output is correct
21 Correct 19 ms 4180 KB Output is correct
22 Correct 21 ms 4272 KB Output is correct
23 Correct 22 ms 4176 KB Output is correct
24 Correct 21 ms 4248 KB Output is correct
25 Correct 31 ms 4180 KB Output is correct
26 Correct 38 ms 4252 KB Output is correct
27 Correct 35 ms 4180 KB Output is correct
28 Correct 34 ms 4180 KB Output is correct
29 Correct 19 ms 4276 KB Output is correct
30 Correct 19 ms 4284 KB Output is correct
31 Correct 18 ms 4180 KB Output is correct
32 Correct 20 ms 4272 KB Output is correct
33 Correct 68 ms 4180 KB Output is correct
34 Correct 55 ms 4180 KB Output is correct
35 Correct 54 ms 4256 KB Output is correct
36 Correct 61 ms 4252 KB Output is correct
37 Correct 22 ms 4176 KB Output is correct
38 Correct 13 ms 4276 KB Output is correct
39 Correct 11 ms 4168 KB Output is correct
40 Correct 11 ms 4180 KB Output is correct
41 Correct 11 ms 4180 KB Output is correct
42 Correct 15 ms 4176 KB Output is correct
43 Correct 15 ms 4180 KB Output is correct
44 Correct 20 ms 4180 KB Output is correct
45 Correct 16 ms 4276 KB Output is correct
46 Correct 25 ms 4176 KB Output is correct
47 Correct 16 ms 4276 KB Output is correct
48 Correct 17 ms 4276 KB Output is correct
49 Correct 17 ms 4180 KB Output is correct
50 Correct 16 ms 4180 KB Output is correct
51 Correct 22 ms 4180 KB Output is correct
52 Correct 19 ms 4252 KB Output is correct
53 Correct 17 ms 4276 KB Output is correct
54 Correct 19 ms 4180 KB Output is correct
55 Correct 18 ms 4180 KB Output is correct
56 Correct 17 ms 4180 KB Output is correct
57 Correct 16 ms 4276 KB Output is correct
58 Correct 34 ms 4180 KB Output is correct
59 Correct 18 ms 4180 KB Output is correct
60 Correct 26 ms 4180 KB Output is correct
61 Correct 25 ms 4180 KB Output is correct
62 Correct 19 ms 4276 KB Output is correct
63 Correct 21 ms 4244 KB Output is correct
64 Correct 17 ms 4272 KB Output is correct
65 Correct 16 ms 4276 KB Output is correct
66 Correct 19 ms 4180 KB Output is correct
67 Correct 70 ms 4248 KB Output is correct
68 Correct 68 ms 4248 KB Output is correct
69 Correct 64 ms 4252 KB Output is correct
70 Correct 73 ms 4248 KB Output is correct
71 Correct 29 ms 4168 KB Output is correct
72 Correct 28 ms 4272 KB Output is correct
73 Correct 30 ms 4180 KB Output is correct
74 Correct 27 ms 4276 KB Output is correct
75 Correct 19 ms 4276 KB Output is correct
76 Correct 20 ms 4280 KB Output is correct
77 Correct 20 ms 4180 KB Output is correct
78 Correct 20 ms 4180 KB Output is correct
79 Correct 54 ms 4244 KB Output is correct
80 Correct 29 ms 4252 KB Output is correct
81 Correct 21 ms 4180 KB Output is correct
82 Correct 15 ms 4180 KB Output is correct
83 Correct 14 ms 4180 KB Output is correct
84 Correct 25 ms 4180 KB Output is correct
85 Correct 16 ms 4276 KB Output is correct
86 Correct 16 ms 4264 KB Output is correct
87 Correct 16 ms 4256 KB Output is correct
88 Correct 22 ms 4272 KB Output is correct
89 Correct 32 ms 4276 KB Output is correct
90 Correct 30 ms 4180 KB Output is correct
91 Correct 33 ms 4180 KB Output is correct
92 Correct 21 ms 4280 KB Output is correct
93 Correct 272 ms 4256 KB Output is correct
94 Correct 282 ms 4256 KB Output is correct
95 Correct 270 ms 4180 KB Output is correct
96 Correct 261 ms 4256 KB Output is correct
97 Correct 269 ms 4256 KB Output is correct
98 Correct 268 ms 4248 KB Output is correct
99 Correct 278 ms 4256 KB Output is correct
100 Correct 281 ms 4256 KB Output is correct