# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
442367 |
2021-07-07T15:30:05 Z |
elazarkoren |
Game (eJOI20_game) |
C++17 |
|
500 ms |
33100 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define x first
#define y second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
const int infinity = 1e9;
vvb edges1, edges2;
vvi id1, id2;
int n, m;
inline bool IsEdge1(int i, int j, int bit) {
if (edges1[i][j]) return true;
if (id1[i][j] != -1) return !((bit >> id1[i][j]) & 1);
return false;
}
inline bool IsEdge2(int i, int j, int bit) {
if (edges2[i][j]) return true;
if (id2[i][j] != -1) return !((bit >> id2[i][j]) & 1);
return false;
}
inline bool Inside(int i, int j, int bit) {
if (i < 0 || i >= n || j < 0 || j >= m) return false;
return IsEdge1(i, j, bit) && IsEdge1(i + 1, j, bit) && IsEdge2(i, j, bit) && IsEdge2(i, j + 1, bit);
}
int main() {
cin >> n >> m;
edges1.resize(n + 1, vb(m)), edges2.resize(n, vb(m + 1));
vector<pair<pii, bool>> edges;
id1.resize(n + 1, vi(m, -1)), id2.resize(n, vi(m + 1, -1));
for (int i = 0; i <= n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
edges1[i][j] = c == '1';
if (c == '0') {
id1[i][j] = edges.size();
edges.push_back({{i, j}, false});
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= m; j++) {
char c;
cin >> c;
edges2[i][j] = c == '1';
if (c == '0') {
id2[i][j] = edges.size();
edges.push_back({{i, j}, true});
}
}
}
int sz = edges.size();
int pow = 1 << sz;
vi dp1(pow, -infinity), dp2(pow, infinity);
dp1[0] = dp2[0] = 0;
for (int i = 1; i < pow; i++) {
for (int j = 0; j < sz; j++) {
if (!((i >> j) & 1)) continue;
int squares = 0;
int sub = i - (1 << j);
if (edges[j].y) {
squares = Inside(edges[j].x.x, edges[j].x.y, sub) + Inside(edges[j].x.x, edges[j].x.y - 1, sub);
} else {
squares = Inside(edges[j].x.x, edges[j].x.y, sub) + Inside(edges[j].x.x - 1, edges[j].x.y, sub);
}
chkmax(dp1[i], (squares ? dp1[sub] : dp2[sub]) + squares);
chkmin(dp2[i], (squares ? dp2[sub] : dp1[sub]) - squares);
}
}
cout << dp1[pow - 1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
8516 KB |
Output is correct |
2 |
Correct |
153 ms |
4300 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
33100 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
319 ms |
8516 KB |
Output is correct |
6 |
Correct |
153 ms |
4300 KB |
Output is correct |
7 |
Execution timed out |
1078 ms |
33100 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |