QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470256#5416. Fabulous Fungus FrenzyyhdddWA 2ms4072kbC++143.9kb2024-07-10 11:36:392024-07-10 11:36:39

Judging History

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

  • [2024-07-10 11:36:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4072kb
  • [2024-07-10 11:36:39]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
const int maxn=25;
const int maxc=65;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m,k;
int mp[maxn][maxn];
int a[maxn][maxn][maxn];pii sz[maxn];
int t[maxc],num[maxn][maxc],c[maxc];
char s[maxn];
int id(char c){
	if(c>='a'&&c<='z')return c-'a'+1;
	if(c>='A'&&c<='Z')return c-'A'+1+26;
	if(c>='0'&&c<='9')return c-'0'+1+52;
}
char cid(int id){
	if(id<=26)return 'a'+id-1;
	if(id<=52)return 'A'+id-26-1;
	return '0'+id-52-1;
}
vector<pair<int,pii>> ans;
void mov(int x,int y,int xx,int yy){
	// cout<<x<<" "<<y<<" "<<xx<<" "<<yy<<"\n";
	while(y<yy)ans.push_back({-1,{x,y}}),swap(mp[x][y],mp[x][y+1]),y++;
	while(y>yy)ans.push_back({-2,{x,y}}),swap(mp[x][y],mp[x][y-1]),y--;
	while(x<xx)ans.push_back({-3,{x,y}}),swap(mp[x][y],mp[x+1][y]),x++;
	while(x>xx)ans.push_back({-4,{x,y}}),swap(mp[x][y],mp[x-1][y]),x--;
}
void work(){
	n=read();m=read(),k=read();
	sz[0]={n,m};
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)a[0][i][j]=id(s[j]),num[0][a[0][i][j]]++;
	}
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)mp[i][j]=id(s[j]),t[mp[i][j]]++;
	}
	for(int ii=1;ii<=k;ii++){
		int nn=read(),mm=read();sz[ii]={nn,mm};
		for(int i=1;i<=nn;i++){
			scanf("%s",s+1);
			for(int j=1;j<=mm;j++)a[ii][i][j]=id(s[j]),num[ii][a[ii][i][j]]++;
		}
	}
	for(int tim=0;tim<=k;tim++){
		for(int ii=0;ii<=k;ii++){
			int nn=sz[ii].fi,mm=sz[ii].se;
			int cnt=0;for(int i=1;i<=62;i++)cnt+=max(0ll,num[ii][i]-t[i]),c[i]=max(0ll,num[ii][i]-t[i]);
			if(cnt>t[0]||cnt==nn*mm)continue;
			// cout<<tim<<" "<<ii<<"\n";
			while(cnt<=t[0]&&cnt<nn*mm){
				for(int i=1;i<=nn;i++){
					for(int j=1;j<=mm;j++){
						int ch=a[ii][i][j];
						if(c[ch])c[ch]--,ch=0;
						// cout<<i<<" "<<j<<" "<<ch<<"\n";
						if(mp[i][j]!=ch){
							bool fl=0;
							for(int pi=1;pi<=n;pi++){
								for(int pj=1;pj<=m;pj++)if(mp[pi][pj]==ch){
									if(pi<i&&pj<=mm)continue;
									if(pi==i&&pj<=j)continue;
									mov(pi,pj,i,j);fl=1;break;
								}
								if(fl)break;
							}
						}
					}
				}
				for(int i=1;i<=nn;i++){
					for(int j=1;j<=mm;j++)if(mp[i][j])t[mp[i][j]]--,t[0]++,mp[i][j]=0;
				}
				ans.push_back({ii,{1,1}});
				cnt=0;for(int i=1;i<=62;i++)cnt+=max(0ll,num[ii][i]-t[i]),c[i]=max(0ll,num[ii][i]-t[i]);
			}
			// for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)cout<<cid(mp[i][j]);cout<<"\n";}
			if(t[0]==n*m){
				if(!ans.back().fi)ans.pop_back();
				reverse(ans.begin(),ans.end());
				printf("%lld\n",(int)ans.size());
				for(auto [op,p]:ans)printf("%lld %lld %lld\n",op,p.fi,p.se);
				// for(auto [op,p]:ans){
					// if(op==-4)swap(a[0][p.fi][p.se],a[0][p.fi-1][p.se]);
					// if(op==-3)swap(a[0][p.fi][p.se],a[0][p.fi+1][p.se]);
					// if(op==-2)swap(a[0][p.fi][p.se],a[0][p.fi][p.se-1]);
					// if(op==-1)swap(a[0][p.fi][p.se],a[0][p.fi][p.se+1]);
					// if(op>0){
						// // cout<<op<<"\n";
						// // for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)cout<<cid(a[0][i][j]);cout<<"\n";}
						// int nn=sz[op].fi,mm=sz[op].se;
						// for(int i=1;i<=nn;i++){
							// for(int j=1;j<=mm;j++)a[0][i][j]=a[op][i][j];
						// }
					// }
				// }
				// for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)cout<<cid(a[0][i][j]);cout<<"\n";}
				return ;
			}
			break;
		}
	}
	puts("-1");
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3796kb

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

15
-2 2 3
1 1 1
-4 3 1
-2 3 2
-2 3 3
1 1 1
-2 3 2
-2 3 3
-2 2 2
-2 2 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: 3800kb

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: 3956kb

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:

220
4 1 1
-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 6
-2 4 7
-4 4 5
-4 4 2
-2 4 3
-2 4 4
2 1 1
-4 4 8
-1 4 7
-1 4 6
-1 4 5
-1 4 4
-1 4 3
-1 4 2
-1 4 1
-4 4 7
-1 4 6
-1 4 5
-1 4 4
-1 4 3
-1 4 2
-1 4 1
-2 3 7
-4 4 3
-2 4 4
-2 4 5...

result:

ok puzzle solved

Test #4:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

2 2 1
OO
OO

OP
PP

1 2
PP

output:

8
-2 2 2
1 1 1
-4 2 2
-1 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: 3944kb

input:

2 2 1
OO
OO

OP
PO

2 1
P
P

output:

4
-4 2 2
-1 2 1
1 1 1
-2 1 2

result:

ok puzzle solved

Test #6:

score: 0
Accepted
time: 0ms
memory: 3856kb

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: 3868kb

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: 4072kb

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: 0
Accepted
time: 0ms
memory: 3652kb

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: 1ms
memory: 3980kb

input:

20 20 2
pqo3Mcpvo74RFSsJszsa
znrYm92Qr8fbqhbCTOgq
4KiMYr0kLAxPGNG15x7L
QHKmq6xaJ4PU4msuRAiv
UBfS6VUO87hRnMAjGXKX
zCgknw3FfhdifmVcT6FF
GH6ohIAzZuprlC3vMDVh
mHIJ9KlQvWxt6EgGbJkA
3SwJNhRSdEeF9BNtc9k2
mZmEuriH7Rc4ccMjqI0Y
cFfI8TC1iM4PkKziLOiN
15CUjuwudnrums3c3dsl
ekL52LiFEpzmU4vaGtuX
CfrnQtWb5zAN9oQS2fj...

output:

7436
2 1 1
-2 16 5
-2 16 6
-2 16 7
-2 16 8
-2 16 9
-2 16 10
-2 16 11
-2 16 12
-2 16 13
-2 16 14
-2 16 15
-2 16 16
-2 16 17
-2 16 18
-2 16 19
-2 16 20
-2 15 15
-4 16 13
-4 17 13
-4 18 13
-4 19 13
-2 19 14
-2 19 15
-2 19 16
-2 19 17
-2 19 18
-2 19 19
-2 19 20
-4 5 9
-4 6 9
-4 7 9
-4 8 9
-4 9 9
-4 10 9...

result:

wrong answer puzzle remain unsolved