diff --git a/LibreOJ/6226/6226.cpp b/LibreOJ/6226/6226.cpp new file mode 100644 index 00000000..16d7ab40 --- /dev/null +++ b/LibreOJ/6226/6226.cpp @@ -0,0 +1,136 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 205, + M = N * N; +const int INF = 0x3f3f3f3f; +const int d[][2]{{1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}}; + +int n, m, s, t; +int idx, head[M << 1], ver[M << 4], edge[M << 4], next[M << 4]; +int dis[M << 1], cur[M << 1]; +bool g[N][N]; + +void add(int u, int v, int w) { + next[idx] = head[u]; + ver[idx] = v; + edge[idx] = w; + head[u] = idx++; +} + +int id(int x, int y) { + return x * n + y; +} + +bool bfs() { + std::fill_n(dis, M << 1, 0); + + std::queue q; + + q.emplace(s); + dis[s] = 1; + cur[s] = head[s]; + + while (!q.empty()) { + int u = q.front(); + q.pop(); + + for (int i = head[u]; ~i; i = next[i]) { + int v = ver[i], + w = edge[i]; + + if (w && !dis[v]) { + dis[v] = dis[u] + 1; + cur[v] = head[v]; + + if (v == t) return true; + + q.emplace(v); + } + } + } + + return false; +} + +int dinic(int u, int limit) { + if (u == t) return limit; + + int flow = 0; + for (int i = cur[u]; ~i && flow < limit; i = next[i]) { + cur[u] = i; + + int v = ver[i], + w = edge[i]; + + if (w && dis[v] == dis[u] + 1) { + int k = dinic(v, std::min(w, limit - flow)); + + if (!k) dis[v] = 0; + + edge[i] -= k; + edge[i ^ 1] += k; + flow += k; + } + } + + return flow; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + std::fill_n(head, M << 1, -1); + + cin >> n >> m; + + for (int i = 1, x, y; i <= m; i++) { + cin >> x >> y; + + g[x][y] = true; + } + + s = 0, t = id(n, n) + 1; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (g[i][j]) continue; + + if ((i + j) % 2) { + add(s, id(i, j), 1); + add(id(i, j), s, 0); + + for (auto d : d) { + int x = i + d[0], + y = j + d[1]; + + if (x < 1 || x > n || y < 1 || y > n || g[x][y]) continue; + + add(id(i, j), id(x, y), INF); + add(id(x, y), id(i, j), 0); + } + } else { + add(id(i, j), t, 1); + add(t, id(i, j), 0); + } + } + } + + int ans = 0, flow; + + while (bfs()) { + while (flow = dinic(s, INF)) ans += flow; + } + + std::cerr << ans << endl; + + cout << n * n - m - ans << endl; + + return 0; +} diff --git a/LibreOJ/6226/data/kni0.in b/LibreOJ/6226/data/kni0.in new file mode 100644 index 00000000..60c302e1 --- /dev/null +++ b/LibreOJ/6226/data/kni0.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e10f79062d2cf766d7c50bb7ad058e2957145932608ea0e2180db374062d14f +size 12 diff --git a/LibreOJ/6226/data/kni0.out b/LibreOJ/6226/data/kni0.out new file mode 100644 index 00000000..d76a596d --- /dev/null +++ b/LibreOJ/6226/data/kni0.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0b5c2c2211c8d67ed15e75e656c7862d086e9245420892a7de62cd9ec582a06 +size 2 diff --git a/LibreOJ/6226/data/kni1.in b/LibreOJ/6226/data/kni1.in new file mode 100644 index 00000000..a1769f87 --- /dev/null +++ b/LibreOJ/6226/data/kni1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b41156b05c37763a38475f3438bc3aa533e1d406948c4b1f18a733c2bc6f618 +size 5 diff --git a/LibreOJ/6226/data/kni1.out b/LibreOJ/6226/data/kni1.out new file mode 100644 index 00000000..33f80031 --- /dev/null +++ b/LibreOJ/6226/data/kni1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c468f5e59f2871b946e051445493bbcace531d597edbbcc9935e7d02d025114 +size 3 diff --git a/LibreOJ/6226/data/kni10.in b/LibreOJ/6226/data/kni10.in new file mode 100644 index 00000000..e3de9f41 --- /dev/null +++ b/LibreOJ/6226/data/kni10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9722f7f033a476e8b86d11dd0db2f663d89c77a09c433ecc5b0e65d46568bab +size 79014 diff --git a/LibreOJ/6226/data/kni10.out b/LibreOJ/6226/data/kni10.out new file mode 100644 index 00000000..bcce461b --- /dev/null +++ b/LibreOJ/6226/data/kni10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a945e0ad613ed070363b68aec5e206296f5fc63b94ea0d2b9ac785cbf5ee8a4 +size 7 diff --git a/LibreOJ/6226/data/kni2.in b/LibreOJ/6226/data/kni2.in new file mode 100644 index 00000000..6a3d6f70 --- /dev/null +++ b/LibreOJ/6226/data/kni2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59bf9c8605e3d352976a635aa18bbdb5575ef0eee7681cd889824c1f88a5d962 +size 10 diff --git a/LibreOJ/6226/data/kni2.out b/LibreOJ/6226/data/kni2.out new file mode 100644 index 00000000..2eb7b22f --- /dev/null +++ b/LibreOJ/6226/data/kni2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24ba1e99dc06b19351323aae0d7370243d586475a634b7f6ff7927fbc72cfaed +size 3 diff --git a/LibreOJ/6226/data/kni3.in b/LibreOJ/6226/data/kni3.in new file mode 100644 index 00000000..9b9d8348 --- /dev/null +++ b/LibreOJ/6226/data/kni3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1c7aa487ce435df2c7f97746df0eed5d95f06dcd521713a06515cfaa53ddf26 +size 355 diff --git a/LibreOJ/6226/data/kni3.out b/LibreOJ/6226/data/kni3.out new file mode 100644 index 00000000..2fc12a3c --- /dev/null +++ b/LibreOJ/6226/data/kni3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce60da21a19e0a3d484fc4ee3f868999745b7f23475772ea8c87c7bde54c4b43 +size 4 diff --git a/LibreOJ/6226/data/kni4.in b/LibreOJ/6226/data/kni4.in new file mode 100644 index 00000000..63e62e76 --- /dev/null +++ b/LibreOJ/6226/data/kni4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:743f907082da0a487cb847db9342bc760946e70f63cb9fd25a0838e50532e590 +size 1229 diff --git a/LibreOJ/6226/data/kni4.out b/LibreOJ/6226/data/kni4.out new file mode 100644 index 00000000..3cf427bb --- /dev/null +++ b/LibreOJ/6226/data/kni4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f14439a59c5be5cfdab2da2f777ef0f1caa47450e41ef583957dfe10528e2a9 +size 5 diff --git a/LibreOJ/6226/data/kni5.in b/LibreOJ/6226/data/kni5.in new file mode 100644 index 00000000..7c2f3f5a --- /dev/null +++ b/LibreOJ/6226/data/kni5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1eed2c80110b910b39cfffb33798232f4c6deb5bfe0722ed229b6705e605c85 +size 1766 diff --git a/LibreOJ/6226/data/kni5.out b/LibreOJ/6226/data/kni5.out new file mode 100644 index 00000000..d698ad1f --- /dev/null +++ b/LibreOJ/6226/data/kni5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf9f3334591b4fa91efc2645082c54ce4fa1737f32fdeeb34325a09bf3859903 +size 5 diff --git a/LibreOJ/6226/data/kni6.in b/LibreOJ/6226/data/kni6.in new file mode 100644 index 00000000..71b18160 --- /dev/null +++ b/LibreOJ/6226/data/kni6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68247d1ffab134812848960ff81207ca32b60153dd7de761cd7ed151e6ed5523 +size 6043 diff --git a/LibreOJ/6226/data/kni6.out b/LibreOJ/6226/data/kni6.out new file mode 100644 index 00000000..ae531dc3 --- /dev/null +++ b/LibreOJ/6226/data/kni6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d07e869a8c7fbbb2497af389bf0fb7b6638bef42ec94042bf490ef2a6c9bd76 +size 5 diff --git a/LibreOJ/6226/data/kni7.in b/LibreOJ/6226/data/kni7.in new file mode 100644 index 00000000..228aebc7 --- /dev/null +++ b/LibreOJ/6226/data/kni7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3575788c85063e457ac6ba26b885ac00d35911fd7c83b898d499d4d56a190519 +size 28858 diff --git a/LibreOJ/6226/data/kni7.out b/LibreOJ/6226/data/kni7.out new file mode 100644 index 00000000..c70a211f --- /dev/null +++ b/LibreOJ/6226/data/kni7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4875e1c281910651a6f121df928d292699d58fac4a7d3de3efea584e0d14464 +size 6 diff --git a/LibreOJ/6226/data/kni8.in b/LibreOJ/6226/data/kni8.in new file mode 100644 index 00000000..99cc1d62 --- /dev/null +++ b/LibreOJ/6226/data/kni8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:114a2823b6f1109bde50d47f65cce836eef4f0b4f147662d68892bf33621e8ea +size 114283 diff --git a/LibreOJ/6226/data/kni8.out b/LibreOJ/6226/data/kni8.out new file mode 100644 index 00000000..56fdb6e4 --- /dev/null +++ b/LibreOJ/6226/data/kni8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:737f54fc7205a5ee2b575d5c338446aa054d3c47a3d64895b97c6ee42e2f0843 +size 6 diff --git a/LibreOJ/6226/data/kni9.in b/LibreOJ/6226/data/kni9.in new file mode 100644 index 00000000..9dfe0816 --- /dev/null +++ b/LibreOJ/6226/data/kni9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85913f66ede9aea11623a7509518f597d57c8e253a90cd9d6036f31e40c367e2 +size 27 diff --git a/LibreOJ/6226/data/kni9.out b/LibreOJ/6226/data/kni9.out new file mode 100644 index 00000000..99a511b3 --- /dev/null +++ b/LibreOJ/6226/data/kni9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05260cb6fb015f9c062e0f22830d8d745508c4496eeb1eaa0531c73f5839e23c +size 7