QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537525 | #5416. Fabulous Fungus Frenzy | lfyszy | WA | 0ms | 3832kb | C++20 | 3.8kb | 2024-08-30 14:52:15 | 2024-08-30 14:52:15 |
Judging History
answer
#include <bits/stdc++.h>
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define SP << " " <<
#define fish signed
using namespace std;
const int N = 20 + 10, maxc = (int)('z') + 1;
char pap[N][N];
char pre[N][N][N];
int nn[N], mm[N], n, m, k;
int have[maxc], need[N][maxc], wildcard;
int count(int u) {int res = 0; for(int i = '0'; i < maxc; i ++) res += max(0, need[u][i] - have[i]); return res;}
bool useful(int u) {for (int i = '0'; i < maxc; i ++) if (need[u][i] && have[i]) return true; return false;}
int choose(int &now)
{
if(now > 0) {if(!useful(now) || wildcard < count(now)) now = 0;} if(now > 0) return 1;
for(int i = 1; i <= k; i ++) if(useful(i) && wildcard >= count(i)) {now = i; return 2;} return 0;
}
struct node {int opt, x, y;} ; vector<node> ans;
void note_swap(int x, int y, int xx, int yy)
{
if(x > xx) ans.push_back({-4, x, y});
if(x < xx) ans.push_back({-3, x, y});
if(y > yy) ans.push_back({-2, x, y});
if(y < yy) ans.push_back({-1, x, y});
swap(pap[x][y], pap[xx][yy]);
}
void note_cov(int u) {ans.push_back({u, 1, 1}); for(int i = 1; i <= nn[u]; i ++) for(int j = 1; j <= mm[u]; j ++) pap[i][j] = '*';}
void move(char c, int gx, int gy, int sx, int sy)
{
for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++)
{
if(i < sx && j < sy && (i < gx || i == gx && i < gy)) continue;
if(pap[i][j] == c)
{
if(i < gx)
{
while(i < gx) note_swap(i, j, i + 1, j), i ++;
while(i > gx) note_swap(i, j, i - 1, j), i --;
while(j < gy) note_swap(i, j, i, j + 1), j ++;
while(j > gy) note_swap(i, j, i, j - 1), j --;
}
else
{
while(j < gy) note_swap(i, j, i, j + 1), j ++;
while(j > gy) note_swap(i, j, i, j - 1), j --;
while(i < gx) note_swap(i, j, i + 1, j), i ++;
while(i > gx) note_swap(i, j, i - 1, j), i --;
}
return ;
}
}
}
void cov_now(int u)
{
for(int i = 1; i <= nn[u]; i ++) for(int j = 1; j <= mm[u]; j ++)
if(have[pre[u][i][j]])
{
move(pre[u][i][j], i, j, nn[u], mm[u]);
wildcard ++, have[pre[u][i][j]] --, note_cov(u);
return ;
}
}
void cov_new(int u)
{
for(int i = 1; i <= nn[u]; i ++) for(int j = 1; j <= mm[u]; j ++)
if(have[pre[u][i][j]])
{
move(pre[u][i][j], i, j, nn[u], mm[u]);
wildcard ++, have[pre[u][i][j]] --;
}
else move('*', i, j, nn[u], mm[u]);
note_cov(u);
}
fish main()
{
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for(int i = 1; i <= n; i ++) scanf("%s", pre[0][i] + 1); nn[0] = n, mm[0] = m;
for(int i = 1; i <= n; i ++) scanf("%s", pap[i] + 1);
for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) have[pap[i][j]] ++;
for(int i = 1; i <= k; i ++) {cin >> nn[i] >> mm[i]; for(int j = 1; j <= nn[i]; j ++) scanf("%s", pre[i][j] + 1); }
for(int i = 0; i <= k; i ++) for(int j = 1; j <= nn[i]; j ++) for(int k = 1; k <= mm[i]; k ++) need[i][pre[i][j][k]] ++;
int now = 0;
while(true)
{
int t = choose(now);
if(!t) break ;
else if(t == 1) cov_now(now);
else cov_new(now);
}
if(count(0) <= wildcard)
{
if(useful(0))
{
cov_new(0);
ans.pop_back();
}
cout << ans.size() << "\n";
while(ans.size())
{
cout << (*ans.rbegin()).opt SP (*ans.rbegin()).x SP (*ans.rbegin()).y << "\n";
ans.pop_back();
}
}
else cout << "-1\n";
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3832kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
24 -1 3 2 -1 3 1 -1 3 1 -2 3 2 -2 3 3 -3 2 3 -1 2 1 -4 2 3 -2 1 3 -2 1 2 1 1 1 1 1 1 -2 2 2 -2 2 3 1 1 1 -4 2 1 -4 3 1 -2 3 2 1 1 1 -3 2 1 -3 1 1 -2 2 2 -4 2 1 -4 3 1
result:
wrong answer puzzle remain unsolved