Submission #25932859
Source Code Expand
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;
int A[4][4];
int B[4][4];
int uf[17];
int root(int p) {
return uf[p] < 0 ? p : (uf[p] = root(uf[p]));
}
bool join(int p, int q) {
p = root(p);
q = root(q);
if (p == q) return false;
uf[p] += uf[q];
uf[q] = p;
return true;
}
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
int main()
{
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
scanf("%d", &(A[i][j]));
}
}
int ans = 0;
for (int mask = 0; mask < (1 << 16); ++mask) {
bool isok = true;
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
B[y][x] = (mask >> (y * 4 + x)) & 1;
if (A[y][x] && !B[y][x]) isok = false;
}
}
if (!isok) continue;
for (int y = 1; y < 4; ++y) {
for (int x = 1; x < 4; ++x) {
if (B[y - 1][x - 1] && B[y][x] && !B[y - 1][x] && !B[y][x - 1]) isok = false;
if (!B[y - 1][x - 1] && !B[y][x] && B[y - 1][x] && B[y][x - 1]) isok = false;
}
}
for (int i = 0; i < 17; ++i) uf[i] = -1;
int n_grp = 17;
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
for (int d = 0; d < 4; ++d) {
int y2 = y + dy[d];
int x2 = x + dx[d];
if (B[y][x] && 0 <= y2 && y2 < 4 && 0 <= x2 && x2 < 4 && B[y2][x2]) {
if (join(y * 4 + x, y2 * 4 + x2)) --n_grp;
} else if (!B[y][x]) {
if (0 <= y2 && y2 < 4 && 0 <= x2 && x2 < 4) {
if (!B[y2][x2]) {
if (join(y * 4 + x, y2 * 4 + x2)) --n_grp;
}
} else {
if (join(y * 4 + x, 16)) --n_grp;
}
}
}
}
}
if (n_grp == 2) ++ans;
}
printf("%d\n", ans);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Moat |
| User | semiexp |
| Language | C++ (Clang 10.0.0) |
| Score | 500 |
| Code Size | 2000 Byte |
| Status | AC |
| Exec Time | 35 ms |
| Memory | 3240 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 35 ms | 3004 KiB |
| 001.txt | AC | 27 ms | 3072 KiB |
| 002.txt | AC | 23 ms | 3216 KiB |
| 003.txt | AC | 15 ms | 3000 KiB |
| 004.txt | AC | 21 ms | 3220 KiB |
| 005.txt | AC | 13 ms | 3044 KiB |
| 006.txt | AC | 8 ms | 3004 KiB |
| 007.txt | AC | 17 ms | 3016 KiB |
| 008.txt | AC | 16 ms | 3044 KiB |
| 009.txt | AC | 8 ms | 3016 KiB |
| 010.txt | AC | 11 ms | 3240 KiB |
| 011.txt | AC | 12 ms | 3044 KiB |
| 012.txt | AC | 9 ms | 3040 KiB |
| 013.txt | AC | 11 ms | 3048 KiB |
| 014.txt | AC | 6 ms | 3024 KiB |
| 015.txt | AC | 8 ms | 3024 KiB |
| 016.txt | AC | 6 ms | 3040 KiB |
| 017.txt | AC | 6 ms | 3024 KiB |
| 018.txt | AC | 5 ms | 3024 KiB |
| 019.txt | AC | 4 ms | 3040 KiB |
| 020.txt | AC | 5 ms | 3220 KiB |
| 021.txt | AC | 5 ms | 3048 KiB |
| 022.txt | AC | 8 ms | 3024 KiB |
| 023.txt | AC | 5 ms | 3016 KiB |
| 024.txt | AC | 13 ms | 3100 KiB |
| 025.txt | AC | 13 ms | 3220 KiB |
| 026.txt | AC | 12 ms | 3008 KiB |
| 027.txt | AC | 11 ms | 3212 KiB |
| 028.txt | AC | 9 ms | 3080 KiB |
| 029.txt | AC | 8 ms | 3012 KiB |
| 030.txt | AC | 10 ms | 3208 KiB |
| 031.txt | AC | 7 ms | 3008 KiB |
| 032.txt | AC | 6 ms | 3040 KiB |
| 033.txt | AC | 6 ms | 3224 KiB |
| 034.txt | AC | 15 ms | 3048 KiB |
| 035.txt | AC | 5 ms | 3028 KiB |
| 036.txt | AC | 7 ms | 3232 KiB |
| 037.txt | AC | 5 ms | 3052 KiB |
| 038.txt | AC | 5 ms | 3008 KiB |
| 039.txt | AC | 5 ms | 3216 KiB |
| 040.txt | AC | 6 ms | 3212 KiB |
| 041.txt | AC | 8 ms | 3224 KiB |
| 042.txt | AC | 5 ms | 3212 KiB |
| 043.txt | AC | 5 ms | 3044 KiB |
| 044.txt | AC | 5 ms | 3220 KiB |
| 045.txt | AC | 5 ms | 3012 KiB |
| example0.txt | AC | 12 ms | 3220 KiB |
| example1.txt | AC | 4 ms | 3048 KiB |