0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#3500. 「联合省选 2021 A」矩阵游戏

https://loj.ac/s/1607417
This commit is contained in:
Baoshuo Ren 2022-10-15 16:28:52 +08:00
parent 0eaf016052
commit a01cab89a4
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
42 changed files with 234 additions and 0 deletions

111
LibreOJ/3500/3500.cpp Normal file
View File

@ -0,0 +1,111 @@
#include <iostream>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int MAX = 1e6;
void solve() {
int n, m;
cin >> n >> m;
std::vector<std::vector<int>>
a(n, std::vector<int>(m, 0)),
b(n - 1, std::vector<int>(m - 1, 0));
std::vector<std::vector<std::pair<int, int>>>
g(n + m, std::vector<std::pair<int, int>>());
for (auto &i : b) {
for (auto &x : i) {
cin >> x;
}
}
for (int i = n - 2; i >= 0; i--) {
for (int j = m - 2; j >= 0; j--) {
a[i][j] = b[i][j] - a[i + 1][j] - a[i + 1][j + 1] - a[i][j + 1];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i + j) & 1) {
g[i].emplace_back(j + n, a[i][j]);
g[j + n].emplace_back(i, MAX - a[i][j]);
} else {
g[j + n].emplace_back(i, a[i][j]);
g[i].emplace_back(j + n, MAX - a[i][j]);
}
}
}
std::vector<long long> dist(n + m);
auto spfa = [&]() -> bool {
std::queue<int> q;
std::vector<bool> vis(n + m, true);
std::vector<int> cnt(n + m);
for (int i = 0; i < n + m; i++) {
q.emplace(i);
}
while (!q.empty()) {
int u = q.front();
q.pop();
vis[u] = false;
for (auto e : g[u]) {
int v = e.first,
w = e.second;
if (dist[v] > dist[u] + w) {
dist[v] = dist[u] + w;
if (!vis[v]) {
if (++cnt[v] > n + m) return false;
vis[v] = true;
q.emplace(v);
}
}
}
}
return true;
};
if (!spfa()) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << a[i][j] + ((i + j) & 1 ? dist[i] - dist[j + n] : dist[j + n] - dist[i]) << ' ';
}
cout << endl;
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) solve();
return 0;
}

BIN
LibreOJ/3500/data/checker.cpp (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3500/data/matrix9.in (Stored with Git LFS) Normal file

Binary file not shown.