QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470850 | #5416. Fabulous Fungus Frenzy | XiaoShanYunPan | WA | 2ms | 3872kb | C++14 | 4.3kb | 2024-07-10 16:41:46 | 2024-07-10 16:41:46 |
Judging History
answer
/*
ICPC-Nanjing 2022 智巧灵蕈大竞逐
出题人这次真的是玩原神玩的……
考虑时光倒流之,那么每次都可以把左上角符合条件的变成通配符。
这就非常好,每次我们就算只变一个通配符也行,暴力无脑贪心之。
旋转操作是摆设?
*/
#include<bits/stdc++.h>
using namespace std;
constexpr int N=128;
int star;
struct model
{
char mp[N][N];
int cnt[N],n,m;
void INPUT(int x,int y){n=x,m=y;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>mp[i][j],cnt[mp[i][j]]++;return;}
bool CHK(int c[]){int d=0;for(int i=0;i<N;i++)if(i!='*')d+=max(0,cnt[i]-c[i]);fprintf(stderr,"CHK:%d\n",d);return star>=d;}
}M[N];
char ed[N][N];
int ednt[N];
bool vis[N];
struct operation{int type,x,y;};
stack<operation>stk;
inline void move(int x_1,int y_1,int x_2,int y_2)
{
while(x_1>x_2)
{
stk.push({-3,x_1-1,y_1});
swap(ed[x_1][y_1],ed[x_1-1][y_1]);
x_1--;
}
while(x_1<x_2)
{
stk.push({-4,x_1+1,y_1});
swap(ed[x_1][y_1],ed[x_1+1][y_1]);
x_1++;
}
while(y_1>y_2)
{
stk.push({-1,x_1,y_1-1});
swap(ed[x_1][y_1],ed[x_1][y_1-1]);
y_1--;
}
while(y_1<y_2)
{
stk.push({-2,x_1,y_1+1});
swap(ed[x_1][y_1],ed[x_1][y_1+1]);
y_1++;
}
return;
}
int main()
{
int n,m,k;
cin>>n>>m>>k;
M[0].INPUT(n,m);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>ed[i][j],ednt[ed[i][j]]++;
for(int i=1;i<=k;i++)
{
int a,b;
cin>>a>>b;
M[i].INPUT(a,b);
}
queue<int>id;
for(int i=0;i<=k;i++)if(M[i].CHK(ednt))id.push(i),vis[i]=true;
while(!vis[0]&&!id.empty())
{
int p=id.front();
id.pop();
fprintf(stderr,"REPLACE %d\n",p);
for(int i=1;i<=M[p].n;i++)
{
for(int j=1;j<=M[p].m;j++)
{
// if(ed[i][j]==M[p].mp[i][j]||ed[i][j]=='*')continue;
bool f=false;
for(int x=1;x<=n;x++)
{
for(int y=1;y<=m;y++)
{
if(x<i&&y<=M[p].m)continue;
if(x==i&&y<=j)continue;
if(ed[x][y]==M[p].mp[i][j]){move(x,y,i,j),f=true;break;}
}
if(f)break;
}
if(!f)
{
for(int x=1;x<=n;x++)
{
for(int y=1;y<=m;y++)
{
if(x<i&&y<=M[p].m)continue;
if(x==i&&y<=j)continue;
if(ed[x][y]=='*'){move(x,y,i,j),f=true;break;}
}
if(f)break;
}
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)fprintf(stderr,"%c",ed[i][j]);
fprintf(stderr,"\n");
}
fprintf(stderr,"\n");
for(int i=1;i<=M[p].n;i++)for(int j=1;j<=M[p].m;j++)star+=(ed[i][j]!='*'),ednt[ed[i][j]]--,ed[i][j]='*',stk.push({p,1,1});
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)fprintf(stderr,"%c",ed[i][j]);
fprintf(stderr,"\n");
}
fprintf(stderr,"\n");
do
{
bool f=false;
for(int i=1;i<=M[p].n;i++)
{
for(int j=1;j<=M[p].m;j++)
{
for(int x=1;x<=n;x++)
{
for(int y=1;y<=m;y++)
{
if(x<i&&y<=M[p].m)continue;
if(x==i&&y<=j)continue;
if(ed[x][y]==M[p].mp[i][j])
{
move(x,y,i,j),f=true;
star++,ednt[ed[i][j]]--,ed[i][j]='*',stk.push({p,1,1});
break;
}
}
if(f)break;
}
if(f)break;
}
if(f)break;
}
if(!f)break;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)fprintf(stderr,"%c",ed[i][j]);
fprintf(stderr,"\n");
}
fprintf(stderr,"\n");
}
while(true);
fprintf(stderr,"STAR:%d\n",star);
for(int i=0;i<=k;i++)if(!vis[i]&&M[i].CHK(ednt))id.push(i),vis[i]=true;
}
if(vis[0])
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
// if(ed[i][j]==M[0].mp[i][j]||ed[i][j]=='*')continue;
bool f=false;
for(int x=1;x<=n;x++)
{
for(int y=1;y<=m;y++)
{
if(x<i&&y<=m)continue;
if(x==i&&y<=j)continue;
if(ed[x][y]==M[0].mp[i][j]){move(x,y,i,j),f=true;break;}
}
if(f)break;
}
if(!f)
{
for(int x=1;x<=n;x++)
{
for(int y=1;y<=m;y++)
{
if(x<i&&y<=m)continue;
if(x==i&&y<=j)continue;
if(ed[x][y]=='*'){move(x,y,i,j),f=true;break;}
}
if(f)break;
}
}
}
}
printf("%d\n",stk.size());
while(!stk.empty())
{
operation op=stk.top();
printf("%d %d %d\n",op.type,op.x,op.y);
stk.pop();
}
}
else printf("-1");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3756kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
32 -1 3 2 -1 3 1 -2 2 3 -2 2 2 -3 2 1 -1 2 2 -1 2 1 -3 1 3 -3 2 3 -3 1 2 -3 2 2 -1 1 1 -1 1 2 1 1 1 -1 2 1 -1 2 2 -3 2 3 1 1 1 -1 2 1 -3 2 2 1 1 1 -1 1 1 -1 1 2 -3 1 3 -3 2 3 1 1 1 1 1 1 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: 3760kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3872kb
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:
345 -1 4 7 -1 4 6 -1 4 5 -1 4 4 -1 4 3 -1 4 2 -1 4 1 -2 3 8 -2 3 7 -2 3 6 -2 3 5 -2 3 4 -2 3 3 -2 3 2 -3 3 1 -1 3 7 -1 3 6 -1 3 5 -1 3 4 -1 3 3 -1 3 2 -1 3 1 -2 2 8 -2 2 7 -2 2 6 -2 2 5 -2 2 4 -2 2 3 -2 2 2 -3 2 1 -1 2 7 -1 2 6 -1 2 5 -1 2 4 -1 2 3 -1 2 2 -1 2 1 -2 1 8 -2 1 7 -2 1 6 -2 1 5 -2 1 4 -2...
result:
wrong answer puzzle remain unsolved