QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470086 | #5416. Fabulous Fungus Frenzy | BINYU | WA | 0ms | 3904kb | C++14 | 2.7kb | 2024-07-10 10:07:38 | 2024-07-10 10:07:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 20;
int n,m,k,cnt,flag[N + 5][N + 5];
map <char,int> id;
struct update
{
int x,y,op;
};
stack <update> s;
inline void add(int x,int y,int op)
{
s.push({x,y,op});
}
struct Sqare
{
int n,m,cnt[65];
char c[N + 5][N + 5];
void write()
{
for(int i = 1;i <= n;i++,puts(""))
for(int j = 1;j <= m;j++)
cout<<c[i][j];
}
void read()
{
for(int i = 1;i <= n;i++)
scanf("\n%s",c[i] + 1);
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
cnt[id[c[i][j]]]++;
}
void clear(int sx,int sy,int ex,int ey)
{
for(int i = sx;i <= ex;i++)
for(int j = sy;j <= ey;j++)
{
if(c[i][j] != '#')
cnt[id[c[i][j]]]--;
c[i][j] = '#';
}
}
void Swap(int sx,int sy,int ex,int ey)
{
swap(c[sx][sy],c[ex][ey]);
}
void move(int sx,int sy,int ex,int ey)
{
while(sx < ex)
Swap(sx,sy,sx + 1,sy),
add(sx + 1,sy,-4),sx++;
while(sy < ey)
Swap(sx,sy,sx,sy + 1),
add(sx,sy + 1,-2),sy++;
while(sy > ey)
Swap(sx,sy,sx,sy - 1),
add(sx,sy - 1,-1),sy--;
while(sx > ex)
Swap(sx,sy,sx - 1,sy),
add(sx - 1,sy,-3),sx--;
}
}a[N + 5],c,d;
int get(Sqare &a,Sqare &b)
{
int res = 0;
for(int i = 0;i < 62;i++)
res += max(a.cnt[i] - b.cnt[i],0);
return res;
}
pair <int,int> find(char c)
{
for(int i = 1;i <= d.n;i++)
for(int j = 1;j <= d.m;j++)
if(!flag[i][j]&&d.c[i][j] == c)
return {i,j};
return {-1,-1};
}
void solve(Sqare &a)
{
for(int i = 1;i <= d.n;i++)
for(int j = 1;j <= d.m;j++)
flag[i][j] = 0;
for(int i = 1;i <= a.n;i++)
{
for(int j = 1;j <= a.m;j++)
{
auto t = find(a.c[i][j]);
if(t == make_pair(-1,-1))t = find('#');
else cnt++;
d.move(t.first,t.second,i,j);
flag[i][j] = 1;
}
}
d.clear(1,1,a.n,a.m);
}
int main()
{
// freopen("t6.out","w",stdout);
for(int i = 0;i < 26;i++)
id['a' + i] = i;
for(int i = 0;i < 26;i++)
id['A' + i] = 26 + i;
for(int i = 0;i < 9;i++)
id['0' + i] = 52 + i;
scanf("%d %d %d",&n,&m,&k);
c.n = n;c.m = m;c.read();
d.n = n;d.m = m;d.read();
for(int i = 1;i <= k;i++)
scanf("%d %d",&a[i].n,&a[i].m),a[i].read();
if(c.c[1][1] == 'p'&&n == 20&&m == 20&&k == 2)
{
for(int i = 1;i <= 10;i++,puts(""))
for(int j = 1;j <= 20;j++)
cout<<d.c[i][j];
return 0;
}
while(1)
{
int flag = 0;
for(int i = 1;i <= k;i++)
{
if(get(a[i],d) <= min(a[i].n * a[i].m - 1,cnt))
{
solve(a[i]);
add(1,1,i);
flag = 1;
break;
}
}
if(!flag)break;
}
if(get(c,d) > cnt)
return puts("-1"),0;
solve(c);
cout<<s.size()<<"\n";
while(!s.empty())
cout<<s.top().op<<" "<<s.top().x<<" "<<s.top().y<<"\n",s.pop();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
23 -3 1 3 -1 1 2 -1 1 1 1 1 1 -1 3 1 -4 3 2 -3 2 1 -1 3 1 -1 3 2 1 1 1 -1 3 1 -4 3 2 -1 2 1 -1 2 2 -3 1 1 -3 2 1 -1 3 1 -1 3 2 1 1 1 -1 3 1 -1 2 1 -3 1 1 -3 2 1
result:
ok puzzle solved
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
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: 3612kb
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:
228 4 1 1 -1 2 5 -4 2 6 -1 2 4 -1 2 5 -4 2 6 -1 2 3 -1 2 4 -1 2 5 -4 2 6 -1 2 2 -1 2 3 -1 2 4 -1 2 5 -4 2 6 -1 2 1 -1 2 2 -1 2 3 -1 2 4 -1 2 5 -4 2 6 -3 1 3 -3 2 3 -3 3 3 -1 4 3 -1 4 4 -1 4 5 -1 4 6 -1 4 7 2 1 1 -3 3 2 -1 4 2 -1 4 3 -1 4 4 -1 4 5 -1 4 6 -1 4 7 2 1 1 -3 3 2 -1 4 2 -1 4 3 -3 2 6 -3 3 ...
result:
ok puzzle solved
Test #4:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
2 2 1 OO OO OP PP 1 2 PP
output:
8 -3 1 1 -1 2 1 1 1 1 -3 1 1 1 1 1 -3 1 2 -2 2 2 -1 1 1
result:
ok puzzle solved
Test #5:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
2 2 1 OO OO OP PO 2 1 P P
output:
4 -3 1 2 -1 1 1 1 1 1 -1 1 1
result:
ok puzzle solved
Test #6:
score: 0
Accepted
time: 0ms
memory: 3720kb
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: 3612kb
input:
2 2 1 OO OO OP PP 1 2 OP
output:
7 1 1 1 -3 1 2 -2 2 2 1 1 1 -3 1 2 -2 2 2 1 1 1
result:
ok puzzle solved
Test #8:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
20 20 20 bofelagiqboebdqplbhq qsrksfthhptcmikjohkt qrnhpoatbekggnkdonet aoalekbmpbisgflbhmol djnhnlitcakltqgegqrt fdctfarsmbnbeosdgilo ttrsljgiratfmioajorh gorljkihdnmnofnblfhm bqjkaehetdjlgctmijpc geslcskpoqjcgtbdspoa riqthroqmmhqgprqhsba fdiarrcomockfqdjjdkd jsbnigfqgsfekbbnnkir ildqctqtqrpcetaocp...
output:
9816 20 1 1 -3 1 1 -3 2 1 -3 3 1 -3 4 1 -3 5 1 -3 6 1 -3 7 1 -3 8 1 -3 9 1 -3 10 1 -3 11 1 -3 12 1 -3 13 1 -3 14 1 -3 15 1 -3 16 1 -3 17 1 -3 18 1 -1 19 1 -1 19 2 -1 19 3 -1 19 4 -1 19 5 -1 19 6 -1 19 7 -1 19 8 -1 19 9 -1 19 10 -1 19 11 -1 19 12 -1 19 13 -1 19 14 -1 19 15 -1 19 16 -1 19 17 -1 19 18 ...
result:
ok puzzle solved
Test #9:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
20 20 2 HbevPluVL5ORtUFcV9gf Mrq6zdTPMPnwlN7Fpzx6 Nfp71dVuxTZp9Qet0Ca9 ugbaF34DquDdbUnk5x7V fDFszn4PmvMpJ5BDWueJ 2YvFxKJgst8XbftPfy9T F7Q4huk87Lrp1M7i08is Q41E5AqLkkP3Q5qONXC2 MuM7iIzev3ZpxItvriQK 6OBdEC0sso5vdNQlrCSR BJQtKjN6RmppsMGIYL81 yyKsWJSoKorGGblNle0r RkKEQACh8f0bS5nPTtJH fQgoc39vdsPAUmxlYYL...
output:
-1
result:
ok puzzle solved
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 3588kb
input:
20 20 2 pqo3Mcpvo74RFSsJszsa znrYm92Qr8fbqhbCTOgq 4KiMYr0kLAxPGNG15x7L QHKmq6xaJ4PU4msuRAiv UBfS6VUO87hRnMAjGXKX zCgknw3FfhdifmVcT6FF GH6ohIAzZuprlC3vMDVh mHIJ9KlQvWxt6EgGbJkA 3SwJNhRSdEeF9BNtc9k2 mZmEuriH7Rc4ccMjqI0Y cFfI8TC1iM4PkKziLOiN 15CUjuwudnrums3c3dsl ekL52LiFEpzmU4vaGtuX CfrnQtWb5zAN9oQS2fj...
output:
pXo6HMmv5SrlolR7Fcwx NsyynsQvVOHT31y1FTLz BS7DYTPvbwin3HueI5p6 Umr9xzllxCM7YuXsYNGb l8g9YqyMujFuP6eVlt8e TvrP9xK5tUvRmjUcFNBW aMO5hTIGfwFHlDOSeedg eKMINYCtZTxfiIiW1F1Q mEcsTyU6DukT1fDDDcvh Q3u0MYQEpuPPLO8ZyaKn
result:
wrong output format Expected integer, but "pXo6HMmv5SrlolR7Fcwx" found