0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

#366. 古代游戏记录(record)

https://sjzezoj.com/submission/66788
This commit is contained in:
Baoshuo Ren 2023-01-13 09:58:21 +08:00
parent b6ee310617
commit 7f8b828151
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
236 changed files with 863 additions and 0 deletions

158
S2OJ/366/366.cpp Normal file
View File

@ -0,0 +1,158 @@
#include <iostream>
#include <algorithm>
#include <iterator>
#include <queue>
#include <unordered_map>
#include <utility>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 55,
M = N * N * 4;
const int INF = 0x3f3f3f3f;
const std::unordered_map<char, std::pair<int, int>> d{
{'L', {0, -1}},
{'R', {0, 1}},
{'U', {-1, 0}},
{'D', {1, 0}},
};
int n, m, k, s, t, cnt, id[N][N], cost;
int idx, head[M], ver[M << 1], next[M << 1];
std::pair<int, int> edge[M << 1];
int dist[M];
bool vis[M];
void add(int u, int v, int c, int w) {
next[idx] = head[u];
ver[idx] = v;
edge[idx] = {c, w};
head[u] = idx++;
}
bool spfa() {
std::fill(std::begin(vis), std::end(vis), false);
std::fill(std::begin(dist), std::end(dist), INF);
std::queue<int> q;
q.emplace(s);
dist[s] = 0;
vis[s] = true;
while (!q.empty()) {
int u = q.front();
q.pop();
vis[u] = false;
for (int i = head[u]; ~i; i = next[i]) {
int v = ver[i],
c = edge[i].first,
w = edge[i].second;
if (c > 0 && dist[v] > dist[u] + w) {
dist[v] = dist[u] + w;
if (!vis[v]) {
q.emplace(v);
vis[v] = true;
}
}
}
}
return dist[t] != INF;
}
int dinic(int u, int limit) {
if (u == t) return limit;
int flow = 0;
vis[u] = true;
for (int i = head[u]; ~i && flow < limit; i = next[i]) {
int v = ver[i],
c = edge[i].first,
w = edge[i].second;
if (dist[v] == dist[u] + w && c > 0 && !vis[v]) {
int k = dinic(v, std::min(c, limit - flow));
if (!k) dist[v] = INF;
edge[i].first -= k;
edge[i ^ 1].first += k;
flow += k;
cost += k * w;
}
}
vis[u] = false;
return flow;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
std::fill(std::begin(head), std::end(head), -1);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
id[i][j] = ++cnt;
add(s, id[i][j], 1, 0);
add(id[i][j], s, 0, 0);
}
}
for (int i = 1; i <= k; i++) {
int x, y;
char d;
cin >> x >> y >> d;
x++, y++;
int xx = x + ::d.at(d).first,
yy = y + ::d.at(d).second,
p = ++cnt;
add(id[xx][yy], p, 1, 0);
add(p, id[xx][yy], 0, 0);
id[xx][yy] = ++cnt;
add(p, id[xx][yy], 1, 0);
add(id[xx][yy], p, 0, 0);
add(id[x][y], p, 1, -1);
add(p, id[x][y], 0, 1);
}
t = ++cnt;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
add(id[i][j], t, 1, 0);
add(t, id[i][j], 0, 0);
}
}
while (spfa() && dist[t] < 0) {
while (dinic(s, INF)) {}
}
cout << k + cost << endl;
return 0;
}

BIN
S2OJ/366/data/ex_record1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/ex_record1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record100.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record100.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record101.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record101.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record102.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record102.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record103.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record103.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record104.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record104.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record105.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record105.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record106.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record106.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record107.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record107.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record108.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record108.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record109.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record109.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record110.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record110.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record111.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record111.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record112.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record112.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record113.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record113.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record114.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record114.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record115.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record115.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record116.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record116.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record21.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record22.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record23.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record24.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record25.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record26.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record26.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record27.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record27.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record28.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record28.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record29.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record29.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record30.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record30.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record31.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record31.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record32.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record32.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record33.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record33.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record34.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record34.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record35.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record35.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record36.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record36.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record37.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/366/data/record37.in (Stored with Git LFS) Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More