QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#294315#4828. Four Plus Fourucup_team_qiuly#0 0ms0kbC++143.5kb2023-12-30 11:54:062023-12-30 11:54:07

Judging History

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

  • [2023-12-30 11:54:07]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-12-30 11:54:06]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <random>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
mt19937 rnd(123456789);
int n8,n4;
map<string,int> id8,id4;
string s8[100005],s4[100005];
int book[500005];
int ovo[500005];
int awa[4005][4005];
int ans[50005][3];
struct node{
	int id;
	vector<int> qwq;
	bool operator <(const node b){
		return qwq.size()<b.qwq.size();
	}
}a[50005];
int tot;
void dict(){
	cin>>n8;
	for (int i=1;i<=n8;i++)cin>>s8[i],id8[s8[i]]=i;
	cin>>n4;
	for (int i=1;i<=n4;i++){
		cin>>s4[i],id4[s4[i]]=i;
		int v=0;
		for (int j=0;j<4;j++)v=v*26+s4[i][j]-'a';
		book[v]=i; 
	}
	for (int i=1;i<=n8;i++){
		int cnt=0;
		vector<int> qwq;
		for (int a=0;a<8;a++){
			for (int b=0;b<8;b++){
				if (a==b)continue;
				for (int c=0;c<8;c++){
					if (a==c||b==c)continue;
					for (int d=0;d<8;d++){
						if (a==d||b==d||c==d)continue;
						int v=0;
						v=26*v+s8[i][a]-'a';
						v=26*v+s8[i][b]-'a';
						v=26*v+s8[i][c]-'a';
						v=26*v+s8[i][d]-'a';
						if (ovo[v]==1)continue;
						ovo[v]=1;
						if (book[v]!=0)cnt++,qwq.push_back(book[v]);
					}
				}
			}
		}
		if (cnt>=3){
			++tot;
			a[tot].id=i;
			a[tot].qwq=qwq;
		}
		for (int a=0;a<8;a++){
			for (int b=0;b<8;b++){
				if (a==b)continue;
				for (int c=0;c<8;c++){
					if (a==c||b==c)continue;
					for (int d=0;d<8;d++){
						if (a==d||b==d||c==d)continue;
						int v=0;
						v=26*v+s8[i][a]-'a';
						v=26*v+s8[i][b]-'a';
						v=26*v+s8[i][c]-'a';
						v=26*v+s8[i][d]-'a';
						ovo[v]=0;
					}
				}
			}
		}
	}
	sort(a+1,a+1+tot);
	for (int i=1;i<=tot;i++){
		int id=a[i].id;
		vector<int> qwq=a[i].qwq;
		int cnt=(int)qwq.size();
		shuffle(qwq.begin(),qwq.end(),rnd);
		int fg=0;
		for (int i0=0;i0<cnt&&fg==0;i0++){
			int a=qwq[i0];
			for (int i1=i0+1;i1<cnt&&fg==0;i1++){
				int b=qwq[i1];
				if (awa[a][b]!=0)continue;
				for (int i2=i1+1;i2<cnt&&fg==0;i2++){
					int c=qwq[i2];
					if (awa[a][c]!=0||awa[b][c]!=0)continue;
					awa[a][b]=awa[b][a]=awa[a][c]=awa[c][a]=awa[b][c]=awa[c][b]=id;
					ans[id][0]=a,ans[id][1]=b,ans[id][2]=c;
					fg=1;
					break;
				}
			}
		}
		shuffle(qwq.begin(),qwq.end(),rnd);
		for (int i0=0;i0<cnt&&fg==0;i0++)
			for (int i1=0;i1<cnt;i1++){
				if (i0==i1)continue; 
				int a=qwq[i0],b=qwq[i0],c=qwq[i1];
				if (awa[a][b]!=0||awa[a][c]!=0||awa[b][c]!=0)continue;
				awa[a][b]=awa[b][a]=awa[a][c]=awa[c][a]=awa[b][c]=awa[c][b]=id;
				ans[id][0]=a,ans[id][1]=b,ans[id][2]=c;
				fg=1;
				break;
			}
		shuffle(qwq.begin(),qwq.end(),rnd);
		for (int i0=0;i0<cnt&&fg==0;i0++){
			int a=qwq[i0],b=qwq[i0],c=qwq[i0];
			if (awa[a][b]!=0||awa[a][c]!=0||awa[b][c]!=0)continue;
			awa[a][b]=awa[b][a]=awa[a][c]=awa[c][a]=awa[b][c]=awa[c][b]=id;
			ans[id][0]=a,ans[id][1]=b,ans[id][2]=c;
			fg=1;
			break;
		}
		if (ans[id][0]==0||ans[id][1]==0||ans[id][2]==0){
			assert(0);
			cout<<"No!!!"<<endl;
		}
	}
	return;
}
string opt;
int n;
string asd[100005],asdf[100005][2];
int main(){
	cin>>opt;
	if (opt=="password"){
		cin>>n;
		for (int i=1;i<=n;i++)cin>>asd[i];
		dict();
		for (int i=1;i<=n;i++){
			int id=id8[asd[i]];
			cout<<s4[ans[id][0]]<<' '<<s4[ans[id][1]]<<' '<<s4[ans[id][2]]<<endl;
		}
	}
	else{
		cin>>n;
		for (int i=1;i<=n;i++)cin>>asdf[i][0]>>asdf[i][1];
		dict();
		for (int i=1;i<=n;i++){
			int a=id4[asdf[i][0]],b=id4[asdf[i][1]];
			cout<<s8[awa[a][b]]<<endl;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Stage 1: Program answer Runtime Error

input:

password
2
password
couthier
28558
aardvark aardwolf aasvogel abacuses abalones abampere abandons abapical abasedly abashing abatable abatises abattoir abbacies abbatial abbesses abdicate abdomens abdomina abducens abducent abducing abducted abductee abductor abelmosk aberrant abetment abettals abet...

output:


input:


output:


result: