QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750384#5416. Fabulous Fungus FrenzyyanshanjiahongRE 0ms0kbC++144.2kb2024-11-15 14:25:472024-11-15 14:25:47

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 14:25:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-15 14:25:47]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
#define mp make_pair
#define sec second
#define fir first
#define pii pair<int,int>
#define lowbit(i) i&-i
#define double long double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=25,M=130,S=(1<<8)+5,inf=1e9+7,mo=998244353;
const double eps=1e-8;
void read(int &p){
	int x=0,w=1;
	char ch=0;
	while(!isdigit(ch)){
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	p=x*w;
}
struct node{
    int op,x,y;
};
vector<node>ans;
int n,m,k,a[N][N],b[N][N],s[N][N][N];//b:cur
pii sz[N];
int cnts[N][M],cntn[M],cntz,upp;
pii pos[N][M];
void moveptp(int sx,int sy,int ex,int ey){
    if(sx<ex){
        rep(i,sx,ex-1)
            ans.push_back((node){-3,i,sy}),swap(b[i][sy],b[i+1][sy]);
        sx=ex;
    }
    if(sy<ey){
        rep(i,sy,ey-1)
            ans.push_back((node){-1,sx,i}),swap(b[sx][i],b[sx][i+1]);
        sy=ey;
    }
    if(sx>ex){
        repp(i,sx,ex+1)
            ans.push_back((node){-4,i,sy}),swap(b[i][sy],b[i-1][sy]);
        sx=ex;
    }
    if(sy>ey){
        repp(i,sy,ey+1)
            ans.push_back((node){-2,sx,i}),swap(b[sx][i],b[sx][i-1]);
        sy=ey;
    }
}
string ss;
bool check(int id){
    int nwv=cntz;
    bool ok=0;
    rep(i,48,upp){
        if(cntn[i]>=cnts[id][i]){
            if(cnts[id][i])ok=1;
            continue;
        }
        if(cntn[i]+nwv<cnts[id][i])return 0;
        if(cntn[i])ok=1;
        nwv-=cnts[id][i]-cntn[i];
    }
    return ok;
}
void solve(int id){
    //1.
    rep(i,1,sz[id].fir){
        rep(j,1,sz[id].sec){
            bool ok=0;
            rep(x,1,n){
                rep(y,1,m){
                    if(y<=sz[id].sec&&(x<i||(x==i&&y<j)))continue;
                    if(b[x][y]!=s[id][i][j])continue;
                    moveptp(x,y,i,j);
                    ok=1;
                    break;
                }
                if(ok)break;
            }
            if(ok)continue;
            rep(x,1,n){
                rep(y,1,m){
                    if(y<=sz[id].sec&&(x<i||(x==i&&y<j)))continue;
                    if(b[x][y])continue;
                    moveptp(x,y,i,j);
                    ok=1;
                    break;
                }
                if(ok)break;
            }
        }
    }
    ans.push_back((node){id,1,1});
    rep(i,1,sz[id].fir){
        rep(j,1,sz[id].sec)
            if(b[i][j])cntn[b[i][j]]--,b[i][j]=0,cntz++;
    }
    //2.
    while(1){
        bool ok=0;
        rep(i,1,sz[id].fir){
            rep(j,1,sz[id].sec)
                assert(b[i][j]==0);
        }
        rep(i,1,n){
            rep(j,1,m){
                if(!b[i][j])continue;
                if(!cnts[id][b[i][j]])continue;
                int x,y;
                tie(x,y)=pos[id][b[i][j]];
                moveptp(i,j,x,y);
                ok=1,ans.push_back((node){id,1,1});
                cntn[b[x][y]]--,cntz++,b[x][y]=0;
            }
        }
        if(!ok)break;
    }
}
signed main(){
    freopen("stamp.in","r",stdin);
    freopen("stamp.out","w",stdout);
    read(n),read(m),read(k);
    rep(i,1,n){
        cin>>ss;
        rep(j,1,m)
            s[0][i][j]=ss[j-1],cnts[0][s[0][i][j]]++,upp=max(upp,s[0][i][j]);
    }
    sz[0]=mp(n,m);
    rep(i,1,n){
        cin>>ss;
        rep(j,1,m)
            b[i][j]=ss[j-1],cntn[b[i][j]]++,upp=max(upp,b[i][j]);
    }
    rep(i,1,k){
        read(sz[i].fir),read(sz[i].sec);
        rep(j,1,sz[i].fir){
            cin>>ss;
            rep(l,1,sz[i].sec){
                s[i][j][l]=ss[l-1],cnts[i][s[i][j][l]]++,upp=max(upp,s[i][j][l]);
                pos[i][s[i][j][l]]=mp(j,l);
            }
        }
    }
    rep(_,1,k){
        rep(i,1,k){
            if(!check(i))continue;
            solve(i);
        }
    }
    if(!check(0)&&cntz!=n*m){
        puts("-1");
        return 0;
    }
    solve(0),ans.pop_back();
    printf("%d\n",ans.size());
    reverse(ans.begin(),ans.end());
    for(auto i:ans)
        printf("%d %d %d\n",i.op,i.x,i.y);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:


result: