# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
442385 |
2021-07-07T16:01:26 Z |
elazarkoren |
Game (eJOI20_game) |
C++17 |
|
500 ms |
8524 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define x first
#define y second
//#define short int
using namespace std;
typedef vector<short> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<short, short> pii;
const short MAX_N = 21;
const short infinity = 1e3;
bitset<MAX_N> edges1[MAX_N], edges2[MAX_N];
short id1[MAX_N][MAX_N], id2[MAX_N][MAX_N];
short n, m;
inline bool IsEdge1(short i, short 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(short i, short 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(short i, short 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);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
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));
char c;
for (short i = 0; i <= n; i++) {
for (short j = 0; j < m; j++) {
cin >> c;
if (c == '0') {
id1[i][j] = edges.size();
edges.push_back({{i, j}, false});
} else {
edges1[i][j] = true;
id1[i][j] = -1;
}
}
}
for (short i = 0; i < n; i++) {
for (short j = 0; j <= m; j++) {
cin >> c;
if (c == '0') {
id2[i][j] = edges.size();
edges.push_back({{i, j}, true});
} else {
id2[i][j] = -1;
edges2[i][j] = true;
}
}
}
short sz = edges.size();
int pow = 1 << sz;
vi dp1(pow, -infinity);//, dp2(pow, infinity);
dp1[0] = 0;
for (int32_t i = 1; i < pow; i++) {
for (int j = 0; j < sz; j++) {
if (!((i >> j) & 1)) continue;
short 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], short ((squares ? dp1[sub] : -dp1[sub]) + squares));
// chkmin(dp2[i], short ((squares ? dp2[sub] : dp1[sub]) - squares));
}
}
cout << dp1[pow - 1];
}
# |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
275 ms |
2252 KB |
Output is correct |
2 |
Correct |
128 ms |
1228 KB |
Output is correct |
3 |
Execution timed out |
1097 ms |
8524 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
204 KB |
Output isn't correct |
2 |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
275 ms |
2252 KB |
Output is correct |
6 |
Correct |
128 ms |
1228 KB |
Output is correct |
7 |
Execution timed out |
1097 ms |
8524 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |