QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548391 | #6398. Puzzle: Tapa | pandapythoner# | RE | 0ms | 3872kb | C++23 | 3.4kb | 2024-09-05 17:54:35 | 2024-09-05 17:54:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define len(a) int((a).size())
#define all(a) begin(a), end(a)
#define rep(i, n) for (int i = 0; i < (n); i++)
const int SZ = 60;
string grid[SZ];
int dd[SZ][SZ], t = 1, used[SZ][SZ], type[SZ][SZ];
pair<int, int> mt[SZ][SZ];
vector<pair<int, int>> dir = { {2, 0}, {-2, 0}, {0, 2}, {0, -2} };
vector<pair<int, int>> gr[SZ][SZ];
bool khun(int i, int j) {
if (used[i][j] == t) return false;
used[i][j] = t;
for (auto to : gr[i][j]) {
if (mt[to.first][to.second].first == -1 || khun(mt[to.first][to.second].first, mt[to.first][to.second].second)) {
mt[to.first][to.second] = { i, j };
return true;
}
}
return false;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
n = 2 * n - 1;
m = 2 * m - 1;
for (int i = 0; i < n; ++i) cin >> grid[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (grid[i][j] == '.') grid[i][j] = '#';
}
}
for (int i = 0; i < n; i += 2) {
for (int j = 0; j < m; j += 2) {
mt[i][j] = { -1, -1 };
int adj = 8;
int c = 0;
if (i == 0 || i == n - 1) ++c;
if (j == 0 || j == m - 1) ++c;
if (c == 1) adj = 5;
if (c == 2) adj = 3;
type[i][j] = adj;
if ((grid[i][j] - '0') == adj) {
dd[i][j] = 0;
} else {
dd[i][j] = 1;
}
}
}
for (int i = 0; i < n; i += 2) {
for (int j = 0; j < m; j += 2) {
if (dd[i][j] && (i / 2 + j / 2) % 2 == 0) {
for (auto v : dir) {
pair<int, int> to = { i + v.first, j + v.second };
if (to.first >= 0 && to.second >= 0 && to.first < n && to.second < n) {
bool f1 = (type[i][j] == 5 && type[to.first][to.second] == 8);
bool f2 = (type[i][j] == 8 && type[to.first][to.second] == 5);
if (dd[to.first][to.second]) {
if (!f1 && !f2) {
gr[i][j].push_back(to);
}
}
}
}
}
}
}
int mtch = 0;
for (int i = 0; i < n; i += 2) {
for (int j = 0; j < m; j += 2) {
mtch -= dd[i][j];
if (dd[i][j] && (i / 2 + j / 2) % 2 == 0) {
++t;
mtch += 2 * khun(i, j);
}
}
}
if (mtch != 0) {
cout << "NO\n";
return 0;
} else {
cout << "YES\n";
}
for (int i = 0; i < n; i += 2) {
for (int j = 0; j < m; j += 2) {
if (dd[i][j] && (i / 2 + j / 2) % 2 != 0) {
pair<int, int> chng = { i + mt[i][j].first, j + mt[i][j].second };
assert(chng.first % 2 == 0 && chng.second % 2 == 0);
chng.first /= 2;
chng.second /= 2;
grid[chng.first][chng.second] = '.';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) cout << grid[i][j];
cout << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
3 3 2.4.3 ..... 5.8.5 ..... 3.5.3
output:
YES 2.4#3 ##### 5#8#5 ##### 3#5#3
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3 3 3.4.3 ..... 5.7.5 ..... 3.5.3
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
2 2 2.2 ... 2.2
output:
YES 2#2 .#. 2#2
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 50 2.4.4.4.4.5.5.5.5.5.5.5.5.4.5.5.4.4.5.5.5.5.4.5.5.5.5.5.4.4.5.4.5.5.5.5.5.5.5.5.5.5.5.4.4.5.5.4.5.3 ................................................................................................... 2.5.5.4.4.5.5.5.4.4.5.5.5.4.5.5.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.5.4.4.5.5.5.5.4...
output:
NO
result:
ok Correct.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
2 50 2.4.4.5.5.5.5.5.5.5.5.5.4.4.5.5.5.5.4.4.5.5.4.4.5.5.5.4.5.4.4.4.5.4.4.5.4.4.5.5.5.5.4.4.5.5.5.5.5.2 ................................................................................................... 3.5.4.5.5.5.5.5.5.5.5.5.5.5.4.5.5.5.5.4.5.5.5.5.4.4.5.4.5.4.5.5.5.5.5.4.4.5.5.5.4.4.5.5.5.5.5.4...
output:
NO
result:
ok Correct.
Test #6:
score: -100
Runtime Error
input:
50 2 3.2 ... 5.4 ... 5.5 ... 4.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.4 ... 5.4 ... 4.4 ... 5.5 ... 5.5 ... 4.4 ... 5.4 ... 5.4 ... 5.5 ... 4.5 ... 4.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ......