QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471964 | #5416. Fabulous Fungus Frenzy | caijianhong | WA | 1ms | 3816kb | C++14 | 3.0kb | 2024-07-11 12:17:26 | 2024-07-11 12:17:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) void(0)
#endif
using LL = long long;
vector<tuple<int, int, int>> fans;
int loc[30][30], tim;
struct matrix {
int n, m;
vector<char> a;
matrix() = default;
matrix(int n, int m) : n(n), m(m), a(n * m) {
for (int i = 0; i < n * m; i++) cin >> a[i];
}
char* operator[](int i) { return a.data() + i * m; }
valarray<int> count() {
valarray<int> buc(128);
for (int i = 0; i < n * m; i++) if (a[i] != '*') buc[(int)a[i]] += 1;
return buc;
}
void moveone(char ch, int tx, int ty) {
for (int x = 0; x < n; x++) {
for (int y = 0; y < m; y++) {
if (loc[x][y] < tim && a[x * m + y] == ch) {
for (int i = x; i < tx; i++) {
fans.emplace_back(-3, i, y);
swap(a[i * m + y], a[(i + 1) * m + y]);
}
for (int i = x; i > tx; i--) {
fans.emplace_back(-4, i, y);
swap(a[i * m + y], a[(i - 1) * m + y]);
}
for (int j = y; j < ty; j++) {
fans.emplace_back(-1, tx, j);
swap(a[tx * m + j], a[tx * m + j + 1]);
}
for (int j = y; j > ty; j--) {
fans.emplace_back(-2, tx, j);
swap(a[tx * m + j], a[tx * m + j - 1]);
}
return ;
}
}
}
throw "Not Found!";
}
};
int n, m, k, star;
matrix A, B, f[30];
int main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cin >> n >> m >> k;
B = matrix(n, m);
A = matrix(n, m);
for (int i = 1; i <= k; i++) {
int r, c;
cin >> r >> c;
f[i] = matrix(r, c);
}
while ((A.count() > B.count()).max()) {
auto ca = A.count();
bool flag = false;
for (int t = 1; t <= k; t++) {
auto cf = f[t].count();
valarray<int> v = cf - ca;
v[v < 0] = 0;
if (v.sum() <= min(f[t].n * f[t].m - 1, n * m - ca.sum())) {
++tim;
for (int i = 0; i < f[t].n; i++) {
for (int j = 0; j < f[t].m; j++) {
if (v[f[t][i][j]]) --v[f[t][i][j]], A.moveone('*', i, j);
else A.moveone(f[t][i][j], i, j);
loc[i][j] = tim;
}
}
fans.emplace_back(t, 0, 0);
for (int i = 0; i < f[t].n; i++) {
for (int j = 0; j < f[t].m; j++) {
A[i][j] = '*';
}
}
flag = true;
break;
}
}
if (!flag) {
cout << -1 << endl;
return 0;
}
}
valarray<int> v = B.count() - A.count();
v[v < 0] = 0;
++tim;
for (int i = 0; i < B.n; i++) {
for (int j = 0; j < B.m; j++) {
if (v[B[i][j]]) --v[B[i][j]], A.moveone('*', i, j);
else A.moveone(B[i][j], i, j);
loc[i][j] = tim;
}
}
reverse(fans.begin(), fans.end());
cout << fans.size() << endl;
for (auto [op, x, y] : fans) cout << op << " " << x + 1 << " " << y + 1 << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3816kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
5 1 1 1 -2 3 2 -2 2 2 -4 2 1 -4 3 1
result:
ok puzzle solved
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3544kb
input:
4 8 4 11122222 33344444 55556666 77777777 NIxSHUOx DExDUIxx DANxSHIx YUANSHEN 2 3 NIy DEx 3 8 zzzzzzzz DANNSH9I YUA9SHEN 1 1 x 2 5 SHO8y DUUI8
output:
181 4 1 1 -2 2 6 -3 1 6 -2 2 5 -2 2 6 -3 1 6 -2 2 4 -2 2 5 -2 2 6 -3 1 6 -2 2 3 -2 2 4 -2 2 5 -2 2 6 -3 1 6 -2 2 2 -2 2 3 -2 2 4 -2 2 5 -2 2 6 -3 1 6 -2 1 4 -2 1 5 -2 1 6 -2 1 7 -4 2 7 -4 3 7 -4 4 7 2 1 1 -2 3 3 -2 3 4 -2 3 5 -2 3 6 -2 3 7 -2 3 8 -4 4 8 2 1 1 -4 4 2 2 1 1 -4 4 6 -4 4 5 -4 4 3 -2 3 3...
result:
wrong answer puzzle remain unsolved