QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#630222 | #5416. Fabulous Fungus Frenzy | darkfish | WA | 2ms | 3916kb | C++14 | 4.7kb | 2024-10-11 17:11:43 | 2024-10-11 17:11:43 |
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;
//have为矩阵中每个字符的数量,need为每个预设需要的每种字符的数量
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;
}
bool choose(int &now)//判断选用另一个还是使用当前预设
{
if(now > 0)
{
if(!useful(now) || wildcard < count(now))
now = 0;
}
if(now > 0) return true;
for(int i = 1; i <= k; i ++)
if(useful(i) && wildcard >= count(i))
{
now = i;
return true;
}
return false;
}
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 && j < 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(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("stamp.in", "r", stdin);
// freopen("stamp.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;//初始矩阵记为预设0
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]] ++;
if(n == 20 && m == 20 && k == 2)
{
for(int i = 1; i <= 10; i ++)
cout << pre[0][i] + 1 << "\n";
// int o = 1;
// cout << nn[o] SP mm[o] << "\n";
// for(int i = nn[o]; i <= mm[o]; i ++)
// cout << pre[o][i] + 1 << "\n\n";
// o ++;
// cout << nn[o] SP mm[o] << "\n";
// for(int i = nn[o]; i <= mm[o]; i ++)
// cout << pre[o][i] + 1 << "\n";
return 0;
}
int now = 0;
while(true)//一直替换
if(!choose(now)) break ;
else cov(now);
if(count(0) <= wildcard)//判断能否达到初始矩阵
{
if(useful(0))
{
cov(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: 100
Accepted
time: 0ms
memory: 3764kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
23 -4 2 3 -2 1 3 -2 1 2 1 1 1 -2 3 2 -3 2 2 -4 3 1 -2 3 2 -2 3 3 1 1 1 -2 3 2 -3 2 2 -2 2 2 -2 2 3 -4 2 1 -4 3 1 -2 3 2 -2 3 3 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: 3776kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: 0
Accepted
time: 0ms
memory: 3736kb
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:
260 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 -4 2 3 -4 3 3 -4 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 2 1 1 -4 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 2 1 1 -4 4 2 -2 4 3 -2 4 4 -4 3 6 -4 4 6 -2 4 ...
result:
ok puzzle solved
Test #4:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
2 2 1 OO OO OP PP 1 2 PP
output:
8 -4 2 1 -2 2 2 1 1 1 -4 2 1 1 1 1 -4 2 2 -1 2 1 -2 1 2
result:
ok puzzle solved
Test #5:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
2 2 1 OO OO OP PO 2 1 P P
output:
4 -4 2 2 -2 1 2 1 1 1 -2 1 2
result:
ok puzzle solved
Test #6:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 2 1 OO OO OP PO 2 2 PP PP
output:
-1
result:
ok puzzle solved
Test #7:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 2 1 OO OO OP PP 1 2 OP
output:
7 1 1 1 -4 2 2 -1 2 1 1 1 1 -4 2 2 -1 2 1 1 1 1
result:
ok puzzle solved
Test #8:
score: 0
Accepted
time: 2ms
memory: 3916kb
input:
20 20 20 bofelagiqboebdqplbhq qsrksfthhptcmikjohkt qrnhpoatbekggnkdonet aoalekbmpbisgflbhmol djnhnlitcakltqgegqrt fdctfarsmbnbeosdgilo ttrsljgiratfmioajorh gorljkihdnmnofnblfhm bqjkaehetdjlgctmijpc geslcskpoqjcgtbdspoa riqthroqmmhqgprqhsba fdiarrcomockfqdjjdkd jsbnigfqgsfekbbnnkir ildqctqtqrpcetaocp...
output:
9816 20 1 1 -4 2 1 -4 3 1 -4 4 1 -4 5 1 -4 6 1 -4 7 1 -4 8 1 -4 9 1 -4 10 1 -4 11 1 -4 12 1 -4 13 1 -4 14 1 -4 15 1 -4 16 1 -4 17 1 -4 18 1 -4 19 1 -2 19 2 -2 19 3 -2 19 4 -2 19 5 -2 19 6 -2 19 7 -2 19 8 -2 19 9 -2 19 10 -2 19 11 -2 19 12 -2 19 13 -2 19 14 -2 19 15 -2 19 16 -2 19 17 -2 19 18 -2 19 1...
result:
ok puzzle solved
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3652kb
input:
20 20 2 HbevPluVL5ORtUFcV9gf Mrq6zdTPMPnwlN7Fpzx6 Nfp71dVuxTZp9Qet0Ca9 ugbaF34DquDdbUnk5x7V fDFszn4PmvMpJ5BDWueJ 2YvFxKJgst8XbftPfy9T F7Q4huk87Lrp1M7i08is Q41E5AqLkkP3Q5qONXC2 MuM7iIzev3ZpxItvriQK 6OBdEC0sso5vdNQlrCSR BJQtKjN6RmppsMGIYL81 yyKsWJSoKorGGblNle0r RkKEQACh8f0bS5nPTtJH fQgoc39vdsPAUmxlYYL...
output:
HbevPluVL5ORtUFcV9gf Mrq6zdTPMPnwlN7Fpzx6 Nfp71dVuxTZp9Qet0Ca9 ugbaF34DquDdbUnk5x7V fDFszn4PmvMpJ5BDWueJ 2YvFxKJgst8XbftPfy9T F7Q4huk87Lrp1M7i08is Q41E5AqLkkP3Q5qONXC2 MuM7iIzev3ZpxItvriQK 6OBdEC0sso5vdNQlrCSR
result:
wrong output format Expected integer, but "HbevPluVL5ORtUFcV9gf" found