QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#294696#4828. Four Plus FourForever_Young#0 905ms42440kbC++174.8kb2023-12-30 15:52:552023-12-30 15:52:55

Judging History

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

  • [2023-12-30 15:52:55]
  • 评测
  • 测评结果:0
  • 用时:905ms
  • 内存:42440kb
  • [2023-12-30 15:52:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937_64 mrand(1234); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=30100;
int n;
char tt[111],ss[111];
string s[N],f1[N],f2[N],s2[N];
int n4,n8;
VI e[N];
array<int,3> key[N];
map<string,int> idf1,idf2;
map<PII,int> gid;

void genmatch(bool gg=false) {
	scanf("%d",&n8);
	rep(i,0,n8) {
		scanf("%s",tt);
		f1[i]=tt;
		idf1[f1[i]]=i;
	}
	scanf("%d",&n4);
	rep(i,0,n4) {
		scanf("%s",tt);
		f2[i]=tt;
		idf2[f2[i]]=i;
	}
	VI ord;
	rep(i,0,n8) {
		rep(j,0,n4) {
			string o=f1[i];
			rep(k,0,4) {
				bool suc=0;
				rep(z,0,8) if (o[z]==f2[j][k]) {
					o[z]='.';
					suc=1;
					break;
				}
				if (!suc) goto fail;
			}
			e[i].pb(j);
			fail:;
		}
		//printf("%d %d\n",i,SZ(e[i]));
		if (SZ(e[i])>=3) {
			ord.pb(i);
		}
	}
	shuffle(all(ord),mrand);
	sort(all(ord),[&](int x,int y) {
		return SZ(e[x])<SZ(e[y]);
	});
	map<PII,set<int>> st;
	auto add=[&](int u,int v1,int v2,int v3) {
		assert(v1<=v2&&v2<=v3);
		st[mp(v1,v2)].insert(u);
		st[mp(v2,v3)].insert(u);
		st[mp(v1,v3)].insert(u);
		key[u]={v1,v2,v3};
	};
	for (auto u:ord) {
		int m=SZ(e[u]);
		rep(rd,0,100) {
			int u1=rnd(m),u2=rnd(m),u3=rnd(m);
			if (u1!=u2&&u1!=u3&&u2!=u3) {
				if (u1>u2) swap(u1,u2);
				if (u1>u3) swap(u1,u3);
				if (u2>u3) swap(u2,u3);
				int v1=e[u][u1],v2=e[u][u2],v3=e[u][u3];
				if (st[mp(v1,v2)].empty()&&st[mp(v1,v3)].empty()&&st[mp(v2,v3)].empty()) {
					add(u,v1,v2,v3);
					goto suc;
				}
			}
		}
		rep(rd,0,100) {
			int u1=rnd(m),u2=rnd(m),u3=rnd(m);
			if (true) {
				if (u1>u2) swap(u1,u2);
				if (u1>u3) swap(u1,u3);
				if (u2>u3) swap(u2,u3);
				int v1=e[u][u1],v2=e[u][u2],v3=e[u][u3];
				add(u,v1,v2,v3);
				goto suc;
			}
		}

		assert(0);
		suc:;
	}
	vector<PII> contr;
	for (auto x:st) if (SZ(x.se)>=2) {
		for (auto y:x.se) for (auto z:x.se) if (y<z) {
			contr.pb(mp(y,z));
		}
	}
	sort(all(contr));
	contr.erase(unique(all(contr)),contr.end());
	auto checkcon=[&](int u,int v) {
		vector<PII> pu,pv;
		pu.pb(mp(key[u][0],key[u][1]));
		pu.pb(mp(key[u][0],key[u][2]));
		pu.pb(mp(key[u][1],key[u][2]));
		pv.pb(mp(key[v][0],key[v][1]));
		pv.pb(mp(key[v][0],key[v][2]));
		pv.pb(mp(key[v][1],key[v][2]));
		for (auto x:pu) for (auto y:pv) if (x==y) return true;
		return false;
	};
	while (SZ(contr)>0) {
		auto [u,v]=contr[rnd(SZ(contr))];
		if (rnd(2)) swap(u,v);
		int m=SZ(e[u]);
		rep(rd,0,100) {
			int u1=rnd(m),u2=rnd(m),u3=rnd(m);
			if (true) {
				if (u1>u2) swap(u1,u2);
				if (u1>u3) swap(u1,u3);
				if (u2>u3) swap(u2,u3);
				int v1=e[u][u1],v2=e[u][u2],v3=e[u][u3];
				int del=0;
				for (auto [p,q]:contr) if (p==u||q==u) del--;
				set<PII> newct;
				for (auto w:st[mp(v1,v2)]) if (w!=u) {
					newct.insert(mp(u,w)),newct.insert(mp(w,u));
				}
				for (auto w:st[mp(v2,v3)]) if (w!=u) {
					newct.insert(mp(u,w)),newct.insert(mp(w,u));
				}
				for (auto w:st[mp(v1,v3)]) if (w!=u) {
					newct.insert(mp(u,w)),newct.insert(mp(w,u));
				}
				del+=SZ(newct)/2;
				if (del<=0) {
					VI w;
					int w1=key[u][0],w2=key[u][1],w3=key[u][2];
					if (st[mp(w1,w2)].count(u)) st[mp(w1,w2)].erase(u);
					if (st[mp(w1,w3)].count(u)) st[mp(w1,w3)].erase(u);
					if (st[mp(w2,w3)].count(u)) st[mp(w2,w3)].erase(u);
					vector<PII> newt;
					for (auto [p,q]:contr) if (p!=u&&q!=u) newt.pb(mp(p,q));
					for (auto [x,y]:newct) if (x<y) newt.pb(mp(x,y));
					add(u,v1,v2,v3);
					contr=newt;
					break;
				}
			}
		}
	}
	if (gg) {
		for (auto x:ord) rep(u,0,3) rep(v,0,3) if (u!=v) {
			assert(!gid.count(mp(key[x][u],key[x][v]))||gid[mp(key[x][u],key[x][v])]==x);
			gid[mp(key[x][u],key[x][v])]=x;
		}
	}
}
void gaoP() {
	scanf("%d",&n);
	rep(i,0,n) {
		scanf("%s",tt);
		s[i]=tt;
	}
	genmatch();
	rep(i,0,n) {
		int id=idf1[s[i]];
		//printf("?? %d\n",id);
		printf("%s %s %s\n",f2[key[id][0]].c_str(),f2[key[id][1]].c_str(),f2[key[id][2]].c_str());
	}
}
void gaoK() {
	scanf("%d",&n);
	rep(i,0,n) {
		scanf("%s",tt);
		s[i]=tt;
		scanf("%s",tt);
		s2[i]=tt;
	}
	genmatch(true);
	rep(i,0,n) {
		int id1=idf2[s[i]],id2=idf2[s2[i]];
		printf("%s\n",f1[gid[mp(id1,id2)]].c_str());
	}

}

int main() {
	scanf("%s",ss);
	if (ss[0]=='p') gaoP();
	else gaoK();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 905ms
memory: 42440kb

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:

ados asps prao
cure rout thro

input:

keys
4
ados asps
thro rout
prao ados
asps prao
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 abet...

output:

password
couthier
password
password

result:

ok OK

Test #2:

score: 100
Accepted
time: 885ms
memory: 42320kb

input:

password
1
quirkier
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 abetters abet...

output:

keir kier ruer

input:

keys
1
kier ruer
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 abetters abettin...

output:

quirkier

result:

ok OK

Test #3:

score: 100
Accepted
time: 897ms
memory: 42404kb

input:

password
3
aardvark
aardwolf
aardvark
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 abet...

output:

arak kava vara
farl flow frow
arak kava vara

input:

keys
18
kava vara
arak vara
frow farl
arak kava
arak vara
vara kava
flow frow
farl flow
vara arak
frow flow
kava vara
farl frow
arak kava
vara kava
kava arak
flow farl
vara arak
kava arak
28558
aardvark aardwolf aasvogel abacuses abalones abampere abandons abapical abasedly abashing abatable abatise...

output:

aardvark
aardvark
aardwolf
aardvark
aardvark
aardvark
aardwolf
aardwolf
aardvark
aardwolf
aardvark
aardwolf
aardvark
aardvark
aardvark
aardwolf
aardvark
aardvark

result:

ok OK

Test #4:

score: 0
Stage 2: Program answer Runtime Error

input:

password
10000
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
abetters
abetting
abetto...

output:

arak kava vara
farl flow frow
asea leva loge
bass casa cues
aeon anas nobs
beep berm pree
abas anon sand
alba blip laic
abed abye albs
agas anas sigh
abba able teal
bate seat teas
airt bota tori
abba ices scab
abba alba alit
abbe base sabe
beat cate debt
moas nome seam
ambo maid nada
bead bend nude
...

input:

keys
60000
acne clan
fees else
cels silt
sone goas
nidi odic
grog grig
burs user
disk kist
daze izar
soke reis
game ragi
mons nose
foal loaf
fell fila
bris kits
date dune
calo clod
sore sorn
thae this
laps flay
echo bice
seal leal
deni sned
clog role
naoi odic
firs fere
side rees
woof work
vita viga...

output:


result: