QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201837#5161. Last Guesswhsyhyyh#WA 1ms3664kbC++142.3kb2023-10-05 16:58:522023-10-05 16:58:53

Judging History

This is the latest submission verdict.

  • [2023-10-05 16:58:53]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3664kb
  • [2023-10-05 16:58:52]
  • Submitted

answer

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 1010
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
	int res=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
	return res*f;
}
int g,len,S=1000,T=1001;
char ch1[N],ch2[N];
int mn[30],cnt[30];
bool w[30][N],blk[30];
int ans[N];

struct edge {
	int to,nxt,w;
}e[N*N];
int h[N],Cnt=1,cur[N];
void add(int u,int v,int w) {
	e[++Cnt]=(edge) {v,h[u],w},h[u]=Cnt;
	e[++Cnt]=(edge) {u,h[v],0},h[v]=Cnt;
}
int d[N];
bool bfs() {
	rep(i,1,T) d[i]=0,cur[i]=h[i];
	queue<int>qu;qu.push(S);
	d[S]=1;
	int x;
	while(!qu.empty()) {
		x=qu.front(),qu.pop();
		for(int i=h[x],v;i;i=e[i].nxt) {
			v=e[i].to;
			if(d[v]||!e[i].w) continue;
			d[v]=d[x]+1,qu.push(v);
		}
	}
	return d[T]>0;
}
int dinic(int x,int flow) {
	if(x==T) return flow;
	int rest=flow,k;
	for(int i=cur[x],v;i;i=e[i].nxt) {
		v=e[i].to;
		cur[x]=i;
		if(d[v]!=d[x]+1||!e[i].w) continue;
		k=dinic(v,min(rest,e[i].w));
		e[i].w-=k,e[i^1].w+=k,rest-=k;
		if(k&&x<=26&&v>=27&&v<=26+len) ans[v-26]=x;
		if(!rest) break;
	}
	return flow-rest;
}
int main() {
	g=rd(),len=rd();
	rep(i,1,26) rep(j,1,len) w[i][j]=1;
	
	rep(i,1,g-1) {
		scanf("%s%s",ch1+1,ch2+1);
		memset(cnt,0,sizeof(cnt));
		rep(j,1,len) {
			if(ch2[j]=='G') {
				ans[j]=ch1[j]-'a'+1;
				cnt[ch1[j]-'a'+1]++;
			}
			else if(ch2[j]=='Y') {
				cnt[ch1[j]-'a'+1]++;
				w[ch1[j]-'a'+1][j]=0;
			}
			else {
				w[ch1[j]-'a'+1][j]=0;
				blk[ch1[j]-'a'+1]=1;
			}
		}
		rep(j,1,26) mn[j]=max(mn[j],cnt[j]);
	}
	rep(i,1,len) if(ans[i]) rep(j,1,26) w[j][i]=j==ans[i];
	
	rep(i,1,26) add(S,i,mn[i]);
	rep(i,1,len) add(i+26,T,1);
	rep(i,1,len) if(ans[i]) add(ans[i],i+26,1);
	while(bfs()) dinic(S,0x3f3f3f3f);
	rep(i,1,26) rep(j,1,len) if(w[i][j]&&!ans[j]) add(i,j+26,1);
	while(bfs()) dinic(S,0x3f3f3f3f);
	
	rep(i,1,len) if(!ans[i]) {
		rep(j,1,26) if(w[i][j]&&!blk[j]) {
			ans[i]=j;
			break;
		}
	}
	rep(i,1,len) printf("%c",ans[i]+'a'-1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3664kb

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabdcdddbdde

result:

FAIL Wrong answer: does not fit word 0