# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
702238 |
2023-02-23T11:03:39 Z |
LittleCube |
Bowling (BOI15_bow) |
C++17 |
|
1000 ms |
121948 KB |
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
ll dp[10][66][66][331], pre[11][66][331], sum[66][331];
int cost[66][66][66], cost223[66][66][331], cost23[66][331], cost3[331], can[11][331];
const int s2 = 66, s3 = 241;
string mp2[s2], mp3[s3];
int _cost(string s, string t)
{
int a = -1, b = -1;
for (auto c : t)
{
if (c == 'x')
(a == -1 ? a : b) = 10;
else if (c == '/')
b = 10 - a;
else if (isdigit(c))
(a == -1 ? a : b) = c - '0';
if (b >= 0)
break;
}
a = max(0, a), b = max(0, b);
if (s[0] == 'x')
return 10 + a + b;
else if (s[1] == '/')
return 10 + a;
else
return s[0] + s[1] - 2 * '0';
}
bool match(string s, string t)
{
for (int i = 0; i < s.size(); i++)
if (s[i] != t[i] && s[i] != '?')
return 0;
return 1;
}
void solve()
{
string s;
int n, ans[13] = {};
cin >> n >> s;
for (int i = 1; i <= n; i++)
cin >> ans[i + 2];
dp[0][0][0][0] = 1;
for (int i = 1; i <= n - 1; i++)
for (int j = 0; j < s2; j++)
for (int sc = 0; sc <= 330; sc++)
pre[i][j][sc] = sum[j][sc] = 0;
for (int i = 0; i <= n - 2; i++)
{
string t = s.substr(2 * i, 2);
for (int l = 0; l < s2; l++)
can[i][l] = match(t, mp2[l]);
}
for (int i = 0; i <= n - 2; i++)
for (int j = 0; j < s2; j++)
for (int k = 0; k < s2; k++)
if (j == 65 && k == 65)
{
for (int sc = 0; sc <= 330; sc++)
{
if (i > 0 && can[i - 1][k])
dp[i][j][k][sc] += pre[i][j][sc];
if (dp[i][j][k][sc] != 0)
for (int l = 0; l < s2; l++)
if (can[i][l] && (sc + cost[j][k][l] == ans[i + 1] || ans[i + 1] == -1))
dp[i + 1][k][l][sc + cost[j][k][l]] += dp[i][j][k][sc];
dp[i][j][k][sc] = 0;
}
}
else
{
for (int sc = 0; sc <= 330; sc++)
{
if (i > 0 && can[i - 1][k])
dp[i][j][k][sc] += pre[i][j][sc];
if (dp[i][j][k][sc] != 0)
if (sc + cost[j][k][0] == ans[i + 1] || ans[i + 1] == -1)
pre[i + 1][k][sc + cost[j][k][0]] += dp[i][j][k][sc];
dp[i][j][k][sc] = 0;
}
}
ll res = 0;
for (int l = 0; l < s3; l++)
can[n - 1][l] = match(s.substr(2 * n - 2, 3), mp3[l]);
for (int j = 0; j < s2; j++)
for (int k = 0; k < s2; k++)
if (j == 65 && k == 65)
{
for (int sc = 0; sc <= 330; sc++)
{
if (can[n - 2][k])
dp[n - 1][j][k][sc] += pre[n - 1][j][sc];
if (dp[n - 1][j][k][sc] != 0)
for (int l = 0; l < s3; l++)
if (can[n - 1][l])
{
int an2 = cost223[j][k][l], an1 = an2 + cost23[k][l], an = an1 + cost3[l];
if ((sc + an2 == ans[n] || ans[n] == -1) &&
(sc + an1 == ans[n + 1] || ans[n + 1] == -1) &&
(sc + an == ans[n + 2] || ans[n + 2] == -1))
res += dp[n - 1][j][k][sc];
}
dp[n - 1][j][k][sc] = 0;
}
}
else
{
for (int sc = 0; sc <= 330; sc++)
{
if (can[n - 2][k])
dp[n - 1][j][k][sc] += pre[n - 1][j][sc];
if (dp[n - 1][j][k][sc] != 0)
{
int an2 = cost223[j][k][0];
if (dp[n - 1][j][k][sc] != 0 &&
(sc + an2 == ans[n] || ans[n] == -1))
sum[k][sc + an2] += dp[n - 1][j][k][sc];
}
dp[n - 1][j][k][sc] = 0;
}
}
for (int k = 0; k < s2; k++)
for (int sc = 0; sc <= 330; sc++)
if (sum[k][sc] != 0)
for (int l = 0; l < s3; l++)
if (can[n - 1][l])
{
int an1 = cost23[k][l], an = an1 + cost3[l];
if ((sc + an1 == ans[n + 1] || ans[n + 1] == -1) &&
(sc + an == ans[n + 2] || ans[n + 2] == -1))
res += sum[k][sc];
}
cout << res << '\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int idx = 0;
for (int i = 0; i <= 10; i++)
for (int j = 0; j <= 10 - i; j++)
{
string s = (i == 10 ? "x-" : (i + j == 10 ? string(1, '0' + i) + "/" : string(1, '0' + i) + string(1, '0' + j)));
mp2[idx] = s;
idx++;
}
idx = 0;
for (int i = 0; i <= 10; i++)
for (int j = 0; j <= (i == 10 ? 10 : 10 - i); j++)
for (int k = 0; k <= (i == 10 ? (j == 10 ? 10 : 10 - j) : (i + j == 10 ? 10 : 0)); k++)
{
string s = (i == 10 ? "x" : string(1, '0' + i)) +
(j == 10 ? "x" : string(1, '0' + j)) +
(k == 10 ? "x" : string(1, '0' + k));
if (i < 10 && i + j == 10)
s[1] = '/';
if (i == 10 && j < 10 && j + k == 10)
s[2] = '/';
if (i + j < 10)
s[2] = '-';
mp3[idx] = s;
idx++;
}
for (int j = 0; j < s2; j++)
for (int k = 0; k < s2; k++)
for (int l = 0; l < s2; l++)
{
cost[j][k][l] = _cost(mp2[j], mp2[k] + mp2[l]);
}
for (int j = 0; j < s2; j++)
for (int k = 0; k < s2; k++)
for (int l = 0; l < s3; l++)
cost223[j][k][l] = _cost(mp2[j], mp2[k] + mp3[l]);
for (int k = 0; k < s2; k++)
for (int l = 0; l < s3; l++)
cost23[k][l] = _cost(mp2[k], mp3[l]);
for (int l = 0; l < s3; l++)
{
int &an = cost3[l];
if (mp3[l][1] == '/')
{
an += 10;
if (mp3[l][2] != '-')
an += (mp3[l][2] == 'x' ? 10 : mp3[l][2] - '0');
}
else
{
an += (mp3[l][0] == 'x' ? 10 : mp3[l][0] - '0');
if (mp3[l][2] == '/')
an += 10;
else
{
an += (mp3[l][1] == 'x' ? 10 : mp3[l][1] - '0');
if (mp3[l][2] != '-')
an += (mp3[l][2] == 'x' ? 10 : mp3[l][2] - '0');
}
}
}
cerr << "start\n";
int q;
cin >> q;
while (q--)
solve();
}
Compilation message
bow.cpp: In function 'bool match(std::string, std::string)':
bow.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < s.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
121856 KB |
Output is correct |
2 |
Correct |
381 ms |
110328 KB |
Output is correct |
3 |
Correct |
395 ms |
110260 KB |
Output is correct |
4 |
Correct |
419 ms |
121840 KB |
Output is correct |
5 |
Correct |
426 ms |
121804 KB |
Output is correct |
6 |
Correct |
459 ms |
121772 KB |
Output is correct |
7 |
Correct |
562 ms |
121840 KB |
Output is correct |
8 |
Correct |
479 ms |
121796 KB |
Output is correct |
9 |
Correct |
433 ms |
121932 KB |
Output is correct |
10 |
Correct |
476 ms |
121852 KB |
Output is correct |
11 |
Correct |
747 ms |
121720 KB |
Output is correct |
12 |
Correct |
170 ms |
30120 KB |
Output is correct |
13 |
Correct |
74 ms |
30108 KB |
Output is correct |
14 |
Correct |
180 ms |
29992 KB |
Output is correct |
15 |
Correct |
85 ms |
30136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
368 ms |
121772 KB |
Output is correct |
2 |
Correct |
478 ms |
121708 KB |
Output is correct |
3 |
Correct |
462 ms |
121772 KB |
Output is correct |
4 |
Correct |
504 ms |
121760 KB |
Output is correct |
5 |
Correct |
497 ms |
121776 KB |
Output is correct |
6 |
Correct |
688 ms |
121768 KB |
Output is correct |
7 |
Correct |
696 ms |
121768 KB |
Output is correct |
8 |
Correct |
695 ms |
121892 KB |
Output is correct |
9 |
Correct |
733 ms |
121800 KB |
Output is correct |
10 |
Correct |
774 ms |
121772 KB |
Output is correct |
11 |
Correct |
779 ms |
121776 KB |
Output is correct |
12 |
Correct |
786 ms |
121792 KB |
Output is correct |
13 |
Correct |
793 ms |
121676 KB |
Output is correct |
14 |
Correct |
805 ms |
121772 KB |
Output is correct |
15 |
Correct |
813 ms |
121776 KB |
Output is correct |
16 |
Correct |
798 ms |
121776 KB |
Output is correct |
17 |
Correct |
799 ms |
121772 KB |
Output is correct |
18 |
Correct |
793 ms |
121664 KB |
Output is correct |
19 |
Correct |
779 ms |
121676 KB |
Output is correct |
20 |
Correct |
821 ms |
121792 KB |
Output is correct |
21 |
Correct |
776 ms |
121932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
121768 KB |
Output is correct |
2 |
Correct |
510 ms |
121740 KB |
Output is correct |
3 |
Correct |
472 ms |
121772 KB |
Output is correct |
4 |
Correct |
449 ms |
121672 KB |
Output is correct |
5 |
Correct |
449 ms |
121864 KB |
Output is correct |
6 |
Correct |
692 ms |
121788 KB |
Output is correct |
7 |
Correct |
687 ms |
121768 KB |
Output is correct |
8 |
Correct |
707 ms |
121748 KB |
Output is correct |
9 |
Correct |
757 ms |
121864 KB |
Output is correct |
10 |
Correct |
816 ms |
121768 KB |
Output is correct |
11 |
Correct |
842 ms |
121776 KB |
Output is correct |
12 |
Correct |
796 ms |
121772 KB |
Output is correct |
13 |
Correct |
840 ms |
121776 KB |
Output is correct |
14 |
Correct |
782 ms |
121804 KB |
Output is correct |
15 |
Correct |
806 ms |
121700 KB |
Output is correct |
16 |
Correct |
823 ms |
121752 KB |
Output is correct |
17 |
Correct |
788 ms |
121776 KB |
Output is correct |
18 |
Correct |
703 ms |
121824 KB |
Output is correct |
19 |
Correct |
696 ms |
121776 KB |
Output is correct |
20 |
Correct |
722 ms |
121816 KB |
Output is correct |
21 |
Correct |
695 ms |
121776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
455 ms |
121772 KB |
Output is correct |
2 |
Correct |
478 ms |
121768 KB |
Output is correct |
3 |
Correct |
489 ms |
121852 KB |
Output is correct |
4 |
Correct |
433 ms |
121752 KB |
Output is correct |
5 |
Correct |
435 ms |
110320 KB |
Output is correct |
6 |
Correct |
480 ms |
121860 KB |
Output is correct |
7 |
Correct |
442 ms |
121752 KB |
Output is correct |
8 |
Correct |
453 ms |
121768 KB |
Output is correct |
9 |
Correct |
460 ms |
121764 KB |
Output is correct |
10 |
Correct |
602 ms |
121768 KB |
Output is correct |
11 |
Correct |
586 ms |
121792 KB |
Output is correct |
12 |
Correct |
544 ms |
121828 KB |
Output is correct |
13 |
Correct |
519 ms |
121676 KB |
Output is correct |
14 |
Correct |
704 ms |
121804 KB |
Output is correct |
15 |
Correct |
716 ms |
121768 KB |
Output is correct |
16 |
Correct |
705 ms |
121772 KB |
Output is correct |
17 |
Correct |
709 ms |
121772 KB |
Output is correct |
18 |
Correct |
676 ms |
121884 KB |
Output is correct |
19 |
Correct |
684 ms |
121768 KB |
Output is correct |
20 |
Correct |
674 ms |
121816 KB |
Output is correct |
21 |
Correct |
678 ms |
121764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
121856 KB |
Output is correct |
2 |
Correct |
381 ms |
110328 KB |
Output is correct |
3 |
Correct |
395 ms |
110260 KB |
Output is correct |
4 |
Correct |
419 ms |
121840 KB |
Output is correct |
5 |
Correct |
426 ms |
121804 KB |
Output is correct |
6 |
Correct |
459 ms |
121772 KB |
Output is correct |
7 |
Correct |
562 ms |
121840 KB |
Output is correct |
8 |
Correct |
479 ms |
121796 KB |
Output is correct |
9 |
Correct |
433 ms |
121932 KB |
Output is correct |
10 |
Correct |
476 ms |
121852 KB |
Output is correct |
11 |
Correct |
747 ms |
121720 KB |
Output is correct |
12 |
Correct |
170 ms |
30120 KB |
Output is correct |
13 |
Correct |
74 ms |
30108 KB |
Output is correct |
14 |
Correct |
180 ms |
29992 KB |
Output is correct |
15 |
Correct |
85 ms |
30136 KB |
Output is correct |
16 |
Correct |
368 ms |
121772 KB |
Output is correct |
17 |
Correct |
478 ms |
121708 KB |
Output is correct |
18 |
Correct |
462 ms |
121772 KB |
Output is correct |
19 |
Correct |
504 ms |
121760 KB |
Output is correct |
20 |
Correct |
497 ms |
121776 KB |
Output is correct |
21 |
Correct |
688 ms |
121768 KB |
Output is correct |
22 |
Correct |
696 ms |
121768 KB |
Output is correct |
23 |
Correct |
695 ms |
121892 KB |
Output is correct |
24 |
Correct |
733 ms |
121800 KB |
Output is correct |
25 |
Correct |
774 ms |
121772 KB |
Output is correct |
26 |
Correct |
779 ms |
121776 KB |
Output is correct |
27 |
Correct |
786 ms |
121792 KB |
Output is correct |
28 |
Correct |
793 ms |
121676 KB |
Output is correct |
29 |
Correct |
805 ms |
121772 KB |
Output is correct |
30 |
Correct |
813 ms |
121776 KB |
Output is correct |
31 |
Correct |
798 ms |
121776 KB |
Output is correct |
32 |
Correct |
799 ms |
121772 KB |
Output is correct |
33 |
Correct |
793 ms |
121664 KB |
Output is correct |
34 |
Correct |
779 ms |
121676 KB |
Output is correct |
35 |
Correct |
821 ms |
121792 KB |
Output is correct |
36 |
Correct |
776 ms |
121932 KB |
Output is correct |
37 |
Correct |
272 ms |
121768 KB |
Output is correct |
38 |
Correct |
510 ms |
121740 KB |
Output is correct |
39 |
Correct |
472 ms |
121772 KB |
Output is correct |
40 |
Correct |
449 ms |
121672 KB |
Output is correct |
41 |
Correct |
449 ms |
121864 KB |
Output is correct |
42 |
Correct |
692 ms |
121788 KB |
Output is correct |
43 |
Correct |
687 ms |
121768 KB |
Output is correct |
44 |
Correct |
707 ms |
121748 KB |
Output is correct |
45 |
Correct |
757 ms |
121864 KB |
Output is correct |
46 |
Correct |
816 ms |
121768 KB |
Output is correct |
47 |
Correct |
842 ms |
121776 KB |
Output is correct |
48 |
Correct |
796 ms |
121772 KB |
Output is correct |
49 |
Correct |
840 ms |
121776 KB |
Output is correct |
50 |
Correct |
782 ms |
121804 KB |
Output is correct |
51 |
Correct |
806 ms |
121700 KB |
Output is correct |
52 |
Correct |
823 ms |
121752 KB |
Output is correct |
53 |
Correct |
788 ms |
121776 KB |
Output is correct |
54 |
Correct |
703 ms |
121824 KB |
Output is correct |
55 |
Correct |
696 ms |
121776 KB |
Output is correct |
56 |
Correct |
722 ms |
121816 KB |
Output is correct |
57 |
Correct |
695 ms |
121776 KB |
Output is correct |
58 |
Correct |
455 ms |
121772 KB |
Output is correct |
59 |
Correct |
478 ms |
121768 KB |
Output is correct |
60 |
Correct |
489 ms |
121852 KB |
Output is correct |
61 |
Correct |
433 ms |
121752 KB |
Output is correct |
62 |
Correct |
435 ms |
110320 KB |
Output is correct |
63 |
Correct |
480 ms |
121860 KB |
Output is correct |
64 |
Correct |
442 ms |
121752 KB |
Output is correct |
65 |
Correct |
453 ms |
121768 KB |
Output is correct |
66 |
Correct |
460 ms |
121764 KB |
Output is correct |
67 |
Correct |
602 ms |
121768 KB |
Output is correct |
68 |
Correct |
586 ms |
121792 KB |
Output is correct |
69 |
Correct |
544 ms |
121828 KB |
Output is correct |
70 |
Correct |
519 ms |
121676 KB |
Output is correct |
71 |
Correct |
704 ms |
121804 KB |
Output is correct |
72 |
Correct |
716 ms |
121768 KB |
Output is correct |
73 |
Correct |
705 ms |
121772 KB |
Output is correct |
74 |
Correct |
709 ms |
121772 KB |
Output is correct |
75 |
Correct |
676 ms |
121884 KB |
Output is correct |
76 |
Correct |
684 ms |
121768 KB |
Output is correct |
77 |
Correct |
674 ms |
121816 KB |
Output is correct |
78 |
Correct |
678 ms |
121764 KB |
Output is correct |
79 |
Correct |
371 ms |
121772 KB |
Output is correct |
80 |
Correct |
514 ms |
121948 KB |
Output is correct |
81 |
Correct |
471 ms |
121776 KB |
Output is correct |
82 |
Correct |
515 ms |
121780 KB |
Output is correct |
83 |
Correct |
512 ms |
121792 KB |
Output is correct |
84 |
Correct |
733 ms |
121772 KB |
Output is correct |
85 |
Correct |
811 ms |
121832 KB |
Output is correct |
86 |
Correct |
725 ms |
121772 KB |
Output is correct |
87 |
Correct |
740 ms |
121676 KB |
Output is correct |
88 |
Correct |
742 ms |
121648 KB |
Output is correct |
89 |
Correct |
774 ms |
121772 KB |
Output is correct |
90 |
Correct |
739 ms |
121852 KB |
Output is correct |
91 |
Correct |
758 ms |
121772 KB |
Output is correct |
92 |
Correct |
652 ms |
121868 KB |
Output is correct |
93 |
Execution timed out |
1073 ms |
121688 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |