# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
464538 |
2021-08-13T11:18:16 Z |
amunduzbaev |
Game (eJOI20_game) |
C++14 |
|
6 ms |
972 KB |
#include "bits/stdc++.h"
using namespace std;
const int N = 25;
vector<int> edges[N*N], cycle, path;
int used[N*N], cntv, cnte;
map<array<int, 4>, int> mem;
//~ 0 cycle
//~ 1 path
//~ cycle, path, left for us, type
int rec(int i, int j, int left, int t){
//~ cout<<i<<" "<<j<<" "<<left<<" "<<t<<"\n";
if(i + 1 == (int)cycle.size() && j + 1 == (int)path.size()) return left;
if(mem.count({i, j, left, t})) return mem[{i, j, left, t}];
int& res = mem[{i, j, left, t}];
res = -(1e9+7);
if(t == 0 && left >= 4){
res = max(res, left - 4 - rec(i, j, 4, -1));
} if(t == 1 && left > 2){
res = max(res, left - 2 - rec(i, j, 2, -1));
}
if(i + 1 < (int)cycle.size()){
res = max(res, left - rec(i + 1, j, cycle[i + 1], 0));
} if(j + 1 < (int)path.size()){
res = max(res, left - rec(i, j + 1, path[j + 1], 1));
}
return res;
}
void dfs(int u){ used[u] = 1;
cntv++;
cnte += (int)edges[u].size();
for(auto x : edges[u]){
if(used[x]) continue;
dfs(x);
}
}
void solve(){
int n, m; cin>>n>>m;
vector<string> h(n+1), v(n);
for(int i=0;i<n+1;i++) cin>>h[i];
for(int i=0;i<n;i++) cin>>v[i];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int u = i * m + j;
if(i && h[i][j] == '0') edges[u].push_back(u - m);
if(i + 1 < n && h[i+1][j] == '0') edges[u].push_back(u + m);
if(j && v[i][j] == '0') edges[u].push_back(u - 1);
if(j + 1 < m && v[i][j+1] == '0') edges[u].push_back(u + 1);
if(h[i][j] == '1' && h[i+1][j] == '1' && v[i][j] == '1' && v[i][j+1] == '1') used[i * m + j] = 1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int u = i * m + j;
if(used[u]) continue;
cnte = cntv = 0;
dfs(u);
if(cntv * 2 > cnte) path.push_back(cntv);
else cycle.push_back(cntv);
}
}
sort(path.begin(), path.end());
sort(cycle.begin(), cycle.end());
//~ for(auto x : path) cout<<x<<" ";
//~ cout<<"\n";
//~ for(auto x : cycle) cout<<x<<" ";
//~ cout<<"\n";
cout<<rec(-1, -1, 0, -1)<<"\n";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
//~ cin>>t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
328 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
0 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
0 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
332 KB |
Output is correct |
56 |
Correct |
0 ms |
332 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
1 ms |
332 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
2 ms |
460 KB |
Output is correct |
67 |
Correct |
3 ms |
588 KB |
Output is correct |
68 |
Correct |
2 ms |
460 KB |
Output is correct |
69 |
Correct |
2 ms |
460 KB |
Output is correct |
70 |
Correct |
2 ms |
460 KB |
Output is correct |
71 |
Correct |
2 ms |
460 KB |
Output is correct |
72 |
Correct |
3 ms |
588 KB |
Output is correct |
73 |
Correct |
6 ms |
972 KB |
Output is correct |
74 |
Correct |
3 ms |
460 KB |
Output is correct |
75 |
Correct |
2 ms |
460 KB |
Output is correct |
76 |
Correct |
2 ms |
460 KB |
Output is correct |
77 |
Correct |
3 ms |
588 KB |
Output is correct |
78 |
Correct |
3 ms |
460 KB |
Output is correct |
79 |
Correct |
2 ms |
460 KB |
Output is correct |
80 |
Correct |
3 ms |
588 KB |
Output is correct |
81 |
Correct |
2 ms |
456 KB |
Output is correct |
82 |
Correct |
4 ms |
588 KB |
Output is correct |
83 |
Correct |
3 ms |
460 KB |
Output is correct |