QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201512#5161. Last GuessPhantomThreshold#WA 3ms6352kbC++202.7kb2023-10-05 14:51:402023-10-05 14:51:40

Judging History

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

  • [2023-10-05 14:51:40]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6352kb
  • [2023-10-05 14:51:40]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;

const int inf = 1e9;
const int maxl = 505;
const int maxn = 11000;
const int maxm = maxn*26;

int n,L;
int ok[maxl][26],cha[maxl],chi[maxl][26];
int numl[26],numr[26];

struct edge
{
	int y,c,nex;
}a[maxm<<1]; int len,fir[maxn];
inline void ins(const int x,const int y,const int c)
{
	a[++len]=(edge){y,c,fir[x]}; fir[x]=len;
	a[++len]=(edge){x,0,fir[y]}; fir[y]=len;
}

int S,T,st,ed;
int h[maxn];
int bfs()
{
	for(int i=1;i<=ed;i++) h[i]=0;
	h[st]=1;
	queue<int>q; q.push(st);
	while(!q.empty())
	{
		const int x=q.front(); q.pop();
		for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y)
		{
			if(a[k].c&&!h[y])
			{
				h[y]=h[x]+1;
				q.push(y);
			}
		}
	}
	return h[ed]>0;
}
int dfs(const int x,const int flow)
{
	if(x==ed) return flow;
	int delta=0;
	for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y)
	{
		if(a[k].c&&h[y]==h[x]+1)
		{
			int minc= dfs(y,min(a[k].c,flow-delta));
			a[k].c-=minc; a[k^1].c+=minc;
			delta+=minc;
		}
		if(delta==flow) return delta;
	}
	if(delta==0) h[x]=0;
	return delta;
}
int Flow()
{
	int ret=0;
	while(bfs())
		ret+=dfs(st,inf);
	return ret;
}

void build()
{
	len=1;
	S=L+26+1,T=S+1;
	st=T+1,ed=st+1;
	
	ins(T,S,inf);
	for(int j=1;j<=L;j++)
	{
		//S -> j 1,1
		ins(st,j,1);
		ins(S,ed,1);
	}
	for(int c=0;c<26;c++)
	{
		//L+c+1 -> T numl, numr
		ins(st,T,numl[c]);
		ins(L+c+1,ed,numl[c]);
		if(numl[c]!=numr[c])
			ins(L+c+1,T,numr[c]-numl[c]);
	}
	for(int j=1;j<=L;j++) for(int c=0;c<26;c++) if(ok[j][c])
	{
		chi[j][c]=len+2;
		ins(j,L+c+1,1);
	}
}


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>n>>L;
	
	for(int c=0;c<26;c++) numl[c]=0,numr[c]=inf;
	for(int j=1;j<=L;j++)
	{
		cha[j]=-1;
		for(int c=0;c<26;c++) ok[j][c]=1;
	}
	
	for(int i=1;i<n;i++)
	{
		string S,T;
		cin>>S>>T; S=' '+S; T=' '+T;
		for(int j=1;j<=L;j++)
		{
			if(T[j]=='G')
			{
				cha[j]=S[j]-'a';
			}
			else if(T[j]=='Y')
			{
				ok[j][S[j]-'a']=0;
			}
			else //'B'
			{
				ok[j][S[j]-'a']=0;
			}
		}
		for(int c=0;c<26;c++)
		{
			int num=0,bound=inf;
			for(int j=1;j<=L;j++) if(S[j]-'a'==c)
			{
				num++;
				if(T[j]=='B')
				{
					bound=min(bound,num-1);
				}
			}
			num=min(num,bound);
			
			numl[c]=max(numl[c],num);
			if(bound!=-1) numr[c]=bound;
		}
	}
	
	for(int j=1;j<=L;j++) if(cha[j]!=-1)
	{
		for(int c=0;c<26;c++) if(c!=cha[j])
			ok[j][c]=0;
	}
	
	build();
	int temp=Flow();
	for(int j=1;j<=L;j++)
	{
		char cc='Z';
		for(int c=0;c<26;c++) if(chi[j][c] && a[chi[j][c]].c)
		{
			cc='a'+c;
		}
		
		cout<<cc;
	}
	cout<<endl;
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3656kb

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

score: 0
Accepted
time: 1ms
memory: 5732kb

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabacabbzdde

result:

ok 

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 6352kb

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzozzzzzzzz...

result:

FAIL Wrong answer: does not fit word 0