# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
463964 |
2021-08-12T05:59:31 Z |
tengiz05 |
Game (eJOI20_game) |
C++17 |
|
500 ms |
252 KB |
#include <bits/stdc++.h>
constexpr int N = 25;
char hor[N][N], ver[N][N];
bool vis[N][N];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
for (int i = 0; i <= n; i++) {
for (int j = 0; j < m; j++) {
std::cin >> hor[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= m; j++) {
std::cin >> ver[i][j];
}
}
std::vector<int> a;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (vis[i][j])
continue;
int Size = 0;
std::queue<std::pair<int, int>> que;
que.emplace(i, j);
vis[i][j] = true;
while (!que.empty()) {
auto [x, y] = que.front();
que.pop();
Size++;
// std::cout << x << " " << y << "\n";
if (x > 0 && hor[x][y] == '0' && !vis[x - 1][y]) {
que.emplace(x - 1, y);
vis[x - 1][y] = true;
}
if (x + 1 < n && hor[x + 1][y] == '0' && !vis[x + 1][y]) {
que.emplace(x + 1, y);
vis[x + 1][y] = true;
}
if (y > 0 && ver[x][y] == '0' && !vis[x][y - 1]) {
que.emplace(x, y - 1);
vis[x][y - 1] = true;
}
if (y + 1 < m && ver[x][y + 1] == '0' && !vis[x][y + 1]) {
que.emplace(x, y + 1);
vis[x][y + 1] = true;
}
}
if (Size == 1 && hor[i][j] == '1' && hor[i + 1][j] == '1' && ver[i][j] == '1' && ver[i][j + 1] == '1')
continue;
a.emplace_back(Size);
// std::cout << Size << "\n";
}
}
int k = a.size();
int pw = 1;
for (int i = 0; i < k; i++, pw *= 3);
std::function<int(std::vector<int>)> calc = [&](std::vector<int> v) {
int ans = -1e9;
if (std::count(v.begin(), v.end(), 2) == k) {
return 0;
}
for (int i = 0; i < k; i++) {
if (v[i] == 0) {
v[i] = 1;
ans = std::max(ans, -calc(v));
v[i] = 0;
} else if (v[i] == 1) {
v[i] = 2;
ans = std::max(ans, a[i] + calc(v));
v[i] = 1;
}
}
return ans;
};
// std::cout << calc({1, 1, 0, 1, 0}) << "\n";
std::cout << calc(std::vector<int>(k)) << "\n";
return 0;
}
//
// + 1
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
252 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 |
Execution timed out |
1091 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |