QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201484#5161. Last Guessnameless_story#RE 0ms3796kbC++202.7kb2023-10-05 14:40:172023-10-05 14:40:18

Judging History

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

  • [2023-10-05 14:40:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3796kb
  • [2023-10-05 14:40:17]
  • 提交

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()
mt19937 rnd(0);
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;
	/*string st(m,'a');
	{
		for (int i=0; i<n; i++)
		{
			st[i]=rnd()%5+'a';
		}
	}*/
	while (--m)
	{
		string s,t;
		// s=string(n,'a'),t=s;
		// for(int i=0;i<n;i++)
		// st[i]=rnd()%5+'a';
		// for(int i=0;i<n;i)
		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]+hig[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;)
	vector<int> lk(sum[26],-1);
	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;
					lk[cur]=v;
					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));
		}
	}
	ed.assign(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]));
	}
}

详细

Test #1:

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

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

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

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabecdbadaaa

result:

ok 

Test #3:

score: -100
Runtime Error

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:

ayxwvutsrpooonmlkjihgfedcbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaoaaaaaaaa...

result: