# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60209 |
2018-07-23T20:44:45 Z |
Benq |
Bowling (BOI15_bow) |
C++11 |
|
1000 ms |
1480 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
int q, n, num[10];
map<pair<pi,pi>,ll> m, M;
string tmp[10];
string gen(vi nex) {
int lst = -1;
string res;
for (int i: nex) {
if (i == -1) res += '-';
else if (lst != -1 && i+lst == 10) {
res += '/';
lst = -1;
} else if (i == 10) res += 'x';
else {
if (lst == -1) lst = 0;
res += char('0'+i);
lst += i;
}
}
return res;
}
bool match(string bad, vi nex) {
string t = gen(nex);
F0R(i,sz(bad)) if (bad[i] != '?' && bad[i] != t[i]) return 0;
return 1;
}
void tri(pair<pair<pi,pi>, ll> A, int x, vi y) {
if (!match(tmp[x],y)) return;
/*if (x == 1) {
cout << "OH ";
for (int i: y) cout << i << " ";
cout << "\n";
cout << gen(y) << "\n";
}*/
pair<pi,pi> a = A.f;
int cur = a.s.s;
for (int i: y) if (i != -1) {
cur += i;
if (a.f.f) {
a.s.f += i, a.s.s += i, cur += i;
a.f.f --;
}
if (a.f.s) {
a.s.s += i, cur += i;
a.f.s --;
}
}
int posi = 0;
if (x != n-1) {
if (y[0] == 10) posi = 2;
else if (y[0]+y[1] == 10) posi = 1;
}
if (x >= 2 && a.f.f == 0 && num[x-2] != -1 && a.s.f != num[x-2]) return;
if (x >= 1 && a.f.s == 0 && num[x-1] != -1 && a.s.s != num[x-1]) return;
if (posi == 0 && num[x] != -1 && cur != num[x]) return;
M[{{a.f.s,posi},{a.s.s,cur}}] += A.s;
}
void process(int x) {
if (x != n-1) {
for (auto a: m) {
tri(a,x,{10,-1});
F0R(i,10) F0R(j,11-i) tri(a,x,{i,j});
}
} else {
for (auto a: m) {
F0R(i,11) tri(a,x,{10,10,i});
F0R(i,10) F0R(j,11-i) tri(a,x,{10,i,j});
F0R(i,10) F0R(j,11) tri(a,x,{i,10-i,j});
F0R(i,10) F0R(j,10-i) tri(a,x,{i,j,-1});
}
}
m = M; M.clear();
}
void solve() {
cin >> n;
string s; cin >> s;
F0R(i,n-1) tmp[i] = s.substr(2*i,2);
tmp[n-1] = s.substr(2*(n-1),3);
F0R(i,n) cin >> num[i];
m.clear();
m[{{0,0},{0,0}}] = 1;
F0R(i,n) {
process(i);
/*cout << i << " " << sz(m) << "\n";
for (auto a: m) cout << a.f.f.f << " " << a.f.f.s << " " << a.f.s.f << " " << a.f.s.s << "\n";
cout << "\n";*/
}
ll ans = 0;
for (auto a: m) ans += a.s;
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> q;
F0R(i,q) solve();
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
376 KB |
Output is correct |
2 |
Correct |
13 ms |
488 KB |
Output is correct |
3 |
Correct |
6 ms |
592 KB |
Output is correct |
4 |
Correct |
6 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
764 KB |
Output is correct |
6 |
Correct |
6 ms |
764 KB |
Output is correct |
7 |
Correct |
82 ms |
900 KB |
Output is correct |
8 |
Correct |
67 ms |
900 KB |
Output is correct |
9 |
Correct |
48 ms |
904 KB |
Output is correct |
10 |
Correct |
76 ms |
908 KB |
Output is correct |
11 |
Correct |
28 ms |
944 KB |
Output is correct |
12 |
Correct |
16 ms |
944 KB |
Output is correct |
13 |
Correct |
5 ms |
944 KB |
Output is correct |
14 |
Correct |
26 ms |
944 KB |
Output is correct |
15 |
Correct |
6 ms |
944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
224 ms |
964 KB |
Output is correct |
2 |
Correct |
134 ms |
984 KB |
Output is correct |
3 |
Correct |
159 ms |
1096 KB |
Output is correct |
4 |
Correct |
49 ms |
1096 KB |
Output is correct |
5 |
Correct |
71 ms |
1096 KB |
Output is correct |
6 |
Correct |
80 ms |
1096 KB |
Output is correct |
7 |
Correct |
130 ms |
1240 KB |
Output is correct |
8 |
Correct |
134 ms |
1240 KB |
Output is correct |
9 |
Correct |
46 ms |
1240 KB |
Output is correct |
10 |
Correct |
435 ms |
1276 KB |
Output is correct |
11 |
Correct |
620 ms |
1276 KB |
Output is correct |
12 |
Correct |
322 ms |
1276 KB |
Output is correct |
13 |
Correct |
512 ms |
1276 KB |
Output is correct |
14 |
Correct |
86 ms |
1276 KB |
Output is correct |
15 |
Correct |
86 ms |
1276 KB |
Output is correct |
16 |
Correct |
72 ms |
1276 KB |
Output is correct |
17 |
Correct |
100 ms |
1276 KB |
Output is correct |
18 |
Execution timed out |
1058 ms |
1360 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
556 ms |
1360 KB |
Output is correct |
2 |
Correct |
12 ms |
1360 KB |
Output is correct |
3 |
Correct |
13 ms |
1360 KB |
Output is correct |
4 |
Correct |
13 ms |
1360 KB |
Output is correct |
5 |
Correct |
19 ms |
1360 KB |
Output is correct |
6 |
Correct |
17 ms |
1360 KB |
Output is correct |
7 |
Correct |
15 ms |
1360 KB |
Output is correct |
8 |
Correct |
19 ms |
1360 KB |
Output is correct |
9 |
Correct |
21 ms |
1360 KB |
Output is correct |
10 |
Correct |
39 ms |
1360 KB |
Output is correct |
11 |
Correct |
21 ms |
1360 KB |
Output is correct |
12 |
Correct |
21 ms |
1360 KB |
Output is correct |
13 |
Correct |
22 ms |
1360 KB |
Output is correct |
14 |
Correct |
67 ms |
1360 KB |
Output is correct |
15 |
Correct |
44 ms |
1360 KB |
Output is correct |
16 |
Correct |
35 ms |
1360 KB |
Output is correct |
17 |
Correct |
42 ms |
1360 KB |
Output is correct |
18 |
Correct |
20 ms |
1360 KB |
Output is correct |
19 |
Correct |
23 ms |
1360 KB |
Output is correct |
20 |
Correct |
15 ms |
1360 KB |
Output is correct |
21 |
Correct |
17 ms |
1360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
852 ms |
1480 KB |
Output is correct |
2 |
Correct |
317 ms |
1480 KB |
Output is correct |
3 |
Correct |
374 ms |
1480 KB |
Output is correct |
4 |
Correct |
359 ms |
1480 KB |
Output is correct |
5 |
Correct |
156 ms |
1480 KB |
Output is correct |
6 |
Correct |
88 ms |
1480 KB |
Output is correct |
7 |
Correct |
175 ms |
1480 KB |
Output is correct |
8 |
Correct |
103 ms |
1480 KB |
Output is correct |
9 |
Correct |
161 ms |
1480 KB |
Output is correct |
10 |
Execution timed out |
1044 ms |
1480 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
376 KB |
Output is correct |
2 |
Correct |
13 ms |
488 KB |
Output is correct |
3 |
Correct |
6 ms |
592 KB |
Output is correct |
4 |
Correct |
6 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
764 KB |
Output is correct |
6 |
Correct |
6 ms |
764 KB |
Output is correct |
7 |
Correct |
82 ms |
900 KB |
Output is correct |
8 |
Correct |
67 ms |
900 KB |
Output is correct |
9 |
Correct |
48 ms |
904 KB |
Output is correct |
10 |
Correct |
76 ms |
908 KB |
Output is correct |
11 |
Correct |
28 ms |
944 KB |
Output is correct |
12 |
Correct |
16 ms |
944 KB |
Output is correct |
13 |
Correct |
5 ms |
944 KB |
Output is correct |
14 |
Correct |
26 ms |
944 KB |
Output is correct |
15 |
Correct |
6 ms |
944 KB |
Output is correct |
16 |
Correct |
224 ms |
964 KB |
Output is correct |
17 |
Correct |
134 ms |
984 KB |
Output is correct |
18 |
Correct |
159 ms |
1096 KB |
Output is correct |
19 |
Correct |
49 ms |
1096 KB |
Output is correct |
20 |
Correct |
71 ms |
1096 KB |
Output is correct |
21 |
Correct |
80 ms |
1096 KB |
Output is correct |
22 |
Correct |
130 ms |
1240 KB |
Output is correct |
23 |
Correct |
134 ms |
1240 KB |
Output is correct |
24 |
Correct |
46 ms |
1240 KB |
Output is correct |
25 |
Correct |
435 ms |
1276 KB |
Output is correct |
26 |
Correct |
620 ms |
1276 KB |
Output is correct |
27 |
Correct |
322 ms |
1276 KB |
Output is correct |
28 |
Correct |
512 ms |
1276 KB |
Output is correct |
29 |
Correct |
86 ms |
1276 KB |
Output is correct |
30 |
Correct |
86 ms |
1276 KB |
Output is correct |
31 |
Correct |
72 ms |
1276 KB |
Output is correct |
32 |
Correct |
100 ms |
1276 KB |
Output is correct |
33 |
Execution timed out |
1058 ms |
1360 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |