QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201454#5161. Last Guessnameless_story#RE 0ms3800kbC++202.5kb2023-10-05 14:25:372023-10-05 14:25:38

Judging History

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

  • [2023-10-05 14:25:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3800kb
  • [2023-10-05 14:25:37]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n,m,i,j;
	cin>>m>>n;
	vector<int> low(26,0),hig(26,n),ans(n,-1);
	vector ban(n,vector<int>(26));
	vector<pair<string,string>> b;
	while (--m)
	{
		string s,t;
		cin>>s>>t;
		b.push_back({s,t});
		vector<int> cnt(26),flg(26);
		for (i=0; i<n; i++) if (t[i]=='G')
		{
			ans[i]=s[i]-'a';
			++cnt[s[i]-'a'];
		}
		else
		{
			ban[i][s[i]-'a']=1;
			if (t[i]=='Y')
			{
				++cnt[s[i]-'a'];
			}
			else if (t[i]=='B')
			{
				flg[s[i]-'a']=1;
			}
			else throw;
		}
		for (i=0; i<26; i++)
		{
			if (flg[i]) hig[i]=cnt[i];
			cmax(low[i],cnt[i]);
		}
	}
	auto lw=low,hh=hig;
	for (int x:ans) if (x!=-1) --low[x],--hig[x];
	vector<int> sum(27);
	for (i=0; i<26; i++) sum[i+1]=sum[i]+low[i];
	vector av(26,vector<int>());
	for (i=0; i<n; i++) for (j=0; ans[i]==-1&&j<26; j++) if (!ban[i][j]) av[j].push_back(i);
	int cur;
	vector<int> ed(n,-1);
	// for (i=0; i<n; i++) cerr<<char('a'+ans[i])<<" \n"[i+1==n];
	// for (i=0; i<n; i++)
	// {
		// for (j=0; j<26; j++)if (!ban[i][j]) cerr<<char('a'+j); cerr<<endl;
	// }
// for (i=0;i<26;i++) for (j=0;)
	function<bool(int)> dfs=[&](int u) ->bool
		{
			for (int v:av[u]) if (ed[v]!=cur)
			{
				ed[v]=cur;
				if (ans[v]==-1||dfs(ans[v]))
				{
					ans[v]=u;
					return 1;
				}
			}
			return 0;
		};
	// cerr<<"?\n";
	for (i=0; i<26; i++)
	{
		for (j=0; j<low[i]; j++)
		{
			cur=sum[i]+j;
			// cerr<<i<<' '<<j<<endl;
			assert(dfs(i));
		}
	}
	for (i=0; i<26; i++) hig[i]-=low[i],sum[i+1]=sum[i]+hig[i];
	ed.assign(sum[26],-1);
	vector<int> lk(sum[26],-1);
	dfs=[&](int u) ->bool
		{
			for (int i=0; i<26; i++) for (int j=0; j<hig[i]; j++) if (!ban[u][i]&&ed[sum[i]+j]!=cur)
			{
				int v=sum[i]+j;
				ed[v]=cur;
				if (lk[v]==-1||dfs(lk[v]))
				{
					lk[v]=u;
					ans[u]=i;
					return 1;
				}
			}
			return 0;
		};
	for (i=0; i<n; i++) if (ans[i]==-1)
	{
		cur=i;
		assert(dfs(i));
	}
	for (i=0; i<n; i++) cout<<char('a'+ans[i]); cout<<endl;
	vector<int> cc(26);
	for (int x:ans) ++cc[x];
	for (i=0; i<26; i++) assert(cc[i]>=lw[i]&&cc[i]<=hh[i]);
	for (auto [x,y]:b)
	{
		for (i=0; i<n; i++) assert((y[i]=='G')==(x[i]-'a'==ans[i]));
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

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

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabecdbadaaa

result:

ok 

Test #3:

score: -100
Runtime Error

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:


result: