# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
725479 |
2023-04-17T14:05:01 Z |
berr |
Bowling (BOI15_bow) |
C++17 |
|
770 ms |
4172 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[11][305][12][12];
vector<string> all, all3;
int check(string t, string s){
for(int i=0; i<s.size(); i++){
if(s[i]!=t[i]&&s[i]!='?') return 0;
}
return 1;
}
int gs(string s){
if(s.size()==3){
int k=0;
for(int i=0; i<s.size(); i++){
if(s[i]=='x') k+=10;
else if(s[i]=='/') k+=10-(s[i-1]-'0');
else if(s[i]!='-') k+=(s[i]-'0');
}
return k;
}
int k=0;
if(s[0]=='x') return 10;
if(s[1]=='/') return 10;
return (s[0]+s[1]-'0'*2);
}
array<int, 2> ab(string s){
array<int, 2> q;
if(s.size()==3){
if(s[0]=='x') q[0] = 10;
else q[0]=(s[0]-'0');
if(s[1]=='x') q[1] = 10;
else if(s[1]=='/') q[1] = 10-(s[0]-'0');
else q[1]=(s[1]-'0');
return q;
}
else{
if(s[1]=='/'){
return {s[0]-'0', 10-(s[0]-'0')};
}
else{
return {s[0]-'0', s[1]-'0'};
}
}
}
void solve(){
int n; cin >> n;
string s; cin >> s;
vector<string> b;
b.push_back("zort");
vector<int> p(n);
for(auto &i: p) cin >> i;
memset(dp, 0, sizeof(dp));
string last="00";
for(int i=0; i<2*(n); i+=2){
string t;
t+=s[i]; t+=s[i+1];
if(i/2<n-1) {
b.push_back(t);
}
else{
t+=s[i+2];
b.push_back(t);
last=t;
}
}
for(auto i: all3){
if(check(i, last)){
int sum=gs(i);
auto x=ab(i);
if(p[n-1] != -1){
dp[n-1][p[n-1]-sum][x[0]][x[1]]++;
}
else{
for(int l=sum; l<305; l++){
dp[n-1][l-sum][x[0]][x[1]]++;
}
}
}
}
int ans = 0;
for(int ind=n-1; ind>0; ind--){
for(auto l: all){
if(check(l, b[ind])){
if(l=="x-"){
for(int i=0; i<=10; i++){
for(int j=0; j<=10; j++){
int sum=10+i+j;
if(p[ind-1]!=-1){
int k=p[ind-1];
int f=k-sum;
if(f>=0){
dp[ind-1][f][10][i] += dp[ind][k][i][j];
if(ind==1&&f==0) ans +=dp[ind][k][i][j];
}
}
else{
for(int k=sum; k<=300; k++){
int f=k-sum;
dp[ind-1][f][10][i] += dp[ind][k][i][j];
if(ind==1&&f==0) ans +=dp[ind][k][i][j];
}
}
}
}
}
else{
int sum=gs(l);
auto x=ab(l);
for(int i=0; i<=10; i++){
int ssum=sum;
if(l[1]=='/') ssum+=i;
for(int j=0; j<=10; j++){
if(p[ind-1]!=-1){
int k=p[ind-1];
int f=k-ssum;
if(f>=0){
dp[ind-1][f][x[0]][x[1]] += dp[ind][k][i][j];
if(f==0&&ind==1){
ans+=dp[ind][k][i][j];
}
}
}
else{
for(int k=ssum; k<=300; k++){
int f=k-ssum;
dp[ind-1][f][x[0]][x[1]] += dp[ind][k][i][j];
if(f==0&&ind==1){
ans+=dp[ind][k][i][j];
}
}
}
}
}
}
}
}
}
cout<<ans<<"\n";
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
all.push_back("x-");
all3.push_back("xxx");
for(char i='0'; i<='9'; i++){
string f="x/";
f[0]=i;
all.push_back(f);
for(char l='0'; l-'0'+i-'0'<10; l++){
string ff=f;
ff[1]=l;
all.push_back(ff);
}
}
for(char i='0'; i<='9'; i++){
string f="xxA"; f[2] = i;
all3.push_back(f);
f="A/x"; f[0]=i;
all3.push_back(f);
f="xA/"; f[1] = i;
all3.push_back(f);
}
for(char i='0'; i<='9'; i++){
for(char l='0'; l-'0'+i-'0'<10; l++){
string f="xAB"; f[1] = i; f[2] = l;
all3.push_back(f);
f="AB-"; f[0] = i; f[1]=l;
all3.push_back(f);
}
}
for(char i='0'; i<='9'; i++){
for(int l='0'; l<='9'; l++){
string f ="A/B"; f[0]=i; f[2] = l;
all3.push_back(f);
}
}
int t; cin >> t;
while(t--){
solve();
}
}
Compilation message
bow.cpp: In function 'long long int check(std::string, std::string)':
bow.cpp:10:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
bow.cpp: In function 'long long int gs(std::string)':
bow.cpp:22:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
bow.cpp:31:9: warning: unused variable 'k' [-Wunused-variable]
31 | int k=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
4052 KB |
Output is correct |
2 |
Correct |
23 ms |
4120 KB |
Output is correct |
3 |
Correct |
5 ms |
4120 KB |
Output is correct |
4 |
Correct |
6 ms |
4052 KB |
Output is correct |
5 |
Correct |
6 ms |
4052 KB |
Output is correct |
6 |
Correct |
5 ms |
4052 KB |
Output is correct |
7 |
Correct |
61 ms |
4100 KB |
Output is correct |
8 |
Correct |
48 ms |
4052 KB |
Output is correct |
9 |
Correct |
51 ms |
4052 KB |
Output is correct |
10 |
Correct |
43 ms |
4052 KB |
Output is correct |
11 |
Correct |
50 ms |
4052 KB |
Output is correct |
12 |
Correct |
96 ms |
4172 KB |
Output is correct |
13 |
Correct |
21 ms |
4124 KB |
Output is correct |
14 |
Correct |
87 ms |
4100 KB |
Output is correct |
15 |
Correct |
23 ms |
4120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
4096 KB |
Output is correct |
2 |
Correct |
134 ms |
4096 KB |
Output is correct |
3 |
Correct |
115 ms |
4096 KB |
Output is correct |
4 |
Correct |
100 ms |
4104 KB |
Output is correct |
5 |
Correct |
130 ms |
4100 KB |
Output is correct |
6 |
Correct |
128 ms |
4104 KB |
Output is correct |
7 |
Correct |
165 ms |
4052 KB |
Output is correct |
8 |
Correct |
141 ms |
4096 KB |
Output is correct |
9 |
Correct |
110 ms |
4100 KB |
Output is correct |
10 |
Correct |
336 ms |
4100 KB |
Output is correct |
11 |
Correct |
356 ms |
4052 KB |
Output is correct |
12 |
Correct |
331 ms |
4096 KB |
Output is correct |
13 |
Correct |
380 ms |
4100 KB |
Output is correct |
14 |
Correct |
170 ms |
4052 KB |
Output is correct |
15 |
Correct |
185 ms |
4096 KB |
Output is correct |
16 |
Correct |
170 ms |
4104 KB |
Output is correct |
17 |
Correct |
165 ms |
4052 KB |
Output is correct |
18 |
Correct |
431 ms |
4100 KB |
Output is correct |
19 |
Correct |
335 ms |
4096 KB |
Output is correct |
20 |
Correct |
438 ms |
4096 KB |
Output is correct |
21 |
Correct |
367 ms |
4052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
4052 KB |
Output is correct |
2 |
Correct |
24 ms |
4028 KB |
Output is correct |
3 |
Correct |
23 ms |
4100 KB |
Output is correct |
4 |
Correct |
18 ms |
4120 KB |
Output is correct |
5 |
Correct |
24 ms |
4052 KB |
Output is correct |
6 |
Correct |
26 ms |
4052 KB |
Output is correct |
7 |
Correct |
27 ms |
4052 KB |
Output is correct |
8 |
Correct |
34 ms |
4104 KB |
Output is correct |
9 |
Correct |
31 ms |
4052 KB |
Output is correct |
10 |
Correct |
59 ms |
4100 KB |
Output is correct |
11 |
Correct |
38 ms |
4052 KB |
Output is correct |
12 |
Correct |
36 ms |
4120 KB |
Output is correct |
13 |
Correct |
39 ms |
4100 KB |
Output is correct |
14 |
Correct |
78 ms |
4100 KB |
Output is correct |
15 |
Correct |
97 ms |
4100 KB |
Output is correct |
16 |
Correct |
90 ms |
4052 KB |
Output is correct |
17 |
Correct |
122 ms |
4116 KB |
Output is correct |
18 |
Correct |
33 ms |
4116 KB |
Output is correct |
19 |
Correct |
29 ms |
4052 KB |
Output is correct |
20 |
Correct |
47 ms |
4052 KB |
Output is correct |
21 |
Correct |
37 ms |
4108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
4100 KB |
Output is correct |
2 |
Correct |
166 ms |
4096 KB |
Output is correct |
3 |
Correct |
238 ms |
4100 KB |
Output is correct |
4 |
Correct |
163 ms |
4052 KB |
Output is correct |
5 |
Correct |
157 ms |
4100 KB |
Output is correct |
6 |
Correct |
138 ms |
4100 KB |
Output is correct |
7 |
Correct |
145 ms |
4104 KB |
Output is correct |
8 |
Correct |
128 ms |
4100 KB |
Output is correct |
9 |
Correct |
161 ms |
4100 KB |
Output is correct |
10 |
Correct |
442 ms |
4100 KB |
Output is correct |
11 |
Correct |
419 ms |
4096 KB |
Output is correct |
12 |
Correct |
367 ms |
4052 KB |
Output is correct |
13 |
Correct |
409 ms |
4100 KB |
Output is correct |
14 |
Correct |
185 ms |
4100 KB |
Output is correct |
15 |
Correct |
181 ms |
4052 KB |
Output is correct |
16 |
Correct |
197 ms |
4104 KB |
Output is correct |
17 |
Correct |
181 ms |
4036 KB |
Output is correct |
18 |
Correct |
74 ms |
4104 KB |
Output is correct |
19 |
Correct |
70 ms |
4108 KB |
Output is correct |
20 |
Correct |
66 ms |
4096 KB |
Output is correct |
21 |
Correct |
56 ms |
4104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
4052 KB |
Output is correct |
2 |
Correct |
23 ms |
4120 KB |
Output is correct |
3 |
Correct |
5 ms |
4120 KB |
Output is correct |
4 |
Correct |
6 ms |
4052 KB |
Output is correct |
5 |
Correct |
6 ms |
4052 KB |
Output is correct |
6 |
Correct |
5 ms |
4052 KB |
Output is correct |
7 |
Correct |
61 ms |
4100 KB |
Output is correct |
8 |
Correct |
48 ms |
4052 KB |
Output is correct |
9 |
Correct |
51 ms |
4052 KB |
Output is correct |
10 |
Correct |
43 ms |
4052 KB |
Output is correct |
11 |
Correct |
50 ms |
4052 KB |
Output is correct |
12 |
Correct |
96 ms |
4172 KB |
Output is correct |
13 |
Correct |
21 ms |
4124 KB |
Output is correct |
14 |
Correct |
87 ms |
4100 KB |
Output is correct |
15 |
Correct |
23 ms |
4120 KB |
Output is correct |
16 |
Correct |
120 ms |
4096 KB |
Output is correct |
17 |
Correct |
134 ms |
4096 KB |
Output is correct |
18 |
Correct |
115 ms |
4096 KB |
Output is correct |
19 |
Correct |
100 ms |
4104 KB |
Output is correct |
20 |
Correct |
130 ms |
4100 KB |
Output is correct |
21 |
Correct |
128 ms |
4104 KB |
Output is correct |
22 |
Correct |
165 ms |
4052 KB |
Output is correct |
23 |
Correct |
141 ms |
4096 KB |
Output is correct |
24 |
Correct |
110 ms |
4100 KB |
Output is correct |
25 |
Correct |
336 ms |
4100 KB |
Output is correct |
26 |
Correct |
356 ms |
4052 KB |
Output is correct |
27 |
Correct |
331 ms |
4096 KB |
Output is correct |
28 |
Correct |
380 ms |
4100 KB |
Output is correct |
29 |
Correct |
170 ms |
4052 KB |
Output is correct |
30 |
Correct |
185 ms |
4096 KB |
Output is correct |
31 |
Correct |
170 ms |
4104 KB |
Output is correct |
32 |
Correct |
165 ms |
4052 KB |
Output is correct |
33 |
Correct |
431 ms |
4100 KB |
Output is correct |
34 |
Correct |
335 ms |
4096 KB |
Output is correct |
35 |
Correct |
438 ms |
4096 KB |
Output is correct |
36 |
Correct |
367 ms |
4052 KB |
Output is correct |
37 |
Correct |
70 ms |
4052 KB |
Output is correct |
38 |
Correct |
24 ms |
4028 KB |
Output is correct |
39 |
Correct |
23 ms |
4100 KB |
Output is correct |
40 |
Correct |
18 ms |
4120 KB |
Output is correct |
41 |
Correct |
24 ms |
4052 KB |
Output is correct |
42 |
Correct |
26 ms |
4052 KB |
Output is correct |
43 |
Correct |
27 ms |
4052 KB |
Output is correct |
44 |
Correct |
34 ms |
4104 KB |
Output is correct |
45 |
Correct |
31 ms |
4052 KB |
Output is correct |
46 |
Correct |
59 ms |
4100 KB |
Output is correct |
47 |
Correct |
38 ms |
4052 KB |
Output is correct |
48 |
Correct |
36 ms |
4120 KB |
Output is correct |
49 |
Correct |
39 ms |
4100 KB |
Output is correct |
50 |
Correct |
78 ms |
4100 KB |
Output is correct |
51 |
Correct |
97 ms |
4100 KB |
Output is correct |
52 |
Correct |
90 ms |
4052 KB |
Output is correct |
53 |
Correct |
122 ms |
4116 KB |
Output is correct |
54 |
Correct |
33 ms |
4116 KB |
Output is correct |
55 |
Correct |
29 ms |
4052 KB |
Output is correct |
56 |
Correct |
47 ms |
4052 KB |
Output is correct |
57 |
Correct |
37 ms |
4108 KB |
Output is correct |
58 |
Correct |
238 ms |
4100 KB |
Output is correct |
59 |
Correct |
166 ms |
4096 KB |
Output is correct |
60 |
Correct |
238 ms |
4100 KB |
Output is correct |
61 |
Correct |
163 ms |
4052 KB |
Output is correct |
62 |
Correct |
157 ms |
4100 KB |
Output is correct |
63 |
Correct |
138 ms |
4100 KB |
Output is correct |
64 |
Correct |
145 ms |
4104 KB |
Output is correct |
65 |
Correct |
128 ms |
4100 KB |
Output is correct |
66 |
Correct |
161 ms |
4100 KB |
Output is correct |
67 |
Correct |
442 ms |
4100 KB |
Output is correct |
68 |
Correct |
419 ms |
4096 KB |
Output is correct |
69 |
Correct |
367 ms |
4052 KB |
Output is correct |
70 |
Correct |
409 ms |
4100 KB |
Output is correct |
71 |
Correct |
185 ms |
4100 KB |
Output is correct |
72 |
Correct |
181 ms |
4052 KB |
Output is correct |
73 |
Correct |
197 ms |
4104 KB |
Output is correct |
74 |
Correct |
181 ms |
4036 KB |
Output is correct |
75 |
Correct |
74 ms |
4104 KB |
Output is correct |
76 |
Correct |
70 ms |
4108 KB |
Output is correct |
77 |
Correct |
66 ms |
4096 KB |
Output is correct |
78 |
Correct |
56 ms |
4104 KB |
Output is correct |
79 |
Correct |
183 ms |
4104 KB |
Output is correct |
80 |
Correct |
200 ms |
4108 KB |
Output is correct |
81 |
Correct |
128 ms |
4100 KB |
Output is correct |
82 |
Correct |
131 ms |
4100 KB |
Output is correct |
83 |
Correct |
118 ms |
4096 KB |
Output is correct |
84 |
Correct |
44 ms |
4052 KB |
Output is correct |
85 |
Correct |
62 ms |
4100 KB |
Output is correct |
86 |
Correct |
41 ms |
4120 KB |
Output is correct |
87 |
Correct |
49 ms |
4004 KB |
Output is correct |
88 |
Correct |
261 ms |
4100 KB |
Output is correct |
89 |
Correct |
428 ms |
4100 KB |
Output is correct |
90 |
Correct |
321 ms |
4096 KB |
Output is correct |
91 |
Correct |
330 ms |
4052 KB |
Output is correct |
92 |
Correct |
39 ms |
4052 KB |
Output is correct |
93 |
Correct |
713 ms |
4116 KB |
Output is correct |
94 |
Correct |
767 ms |
4096 KB |
Output is correct |
95 |
Correct |
739 ms |
4100 KB |
Output is correct |
96 |
Correct |
757 ms |
4100 KB |
Output is correct |
97 |
Correct |
748 ms |
4100 KB |
Output is correct |
98 |
Correct |
753 ms |
4096 KB |
Output is correct |
99 |
Correct |
770 ms |
4100 KB |
Output is correct |
100 |
Correct |
757 ms |
4104 KB |
Output is correct |