QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292996 | #4828. Four Plus Four | ucup-team1447# | 0 | 956ms | 131068kb | C++14 | 3.1kb | 2023-12-28 19:19:29 | 2023-12-28 19:19:30 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
int x;cin>>x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
#define N 29000
#define M 4000
string opt;
int n1,n2;
string s1[maxn],s2[maxn];
int to[N][3];
bitset<M>ok[N];
vi e[N];
int deg1[N],deg2[M],id1[N];
int frm[M][M];
bool g[M][M];
int cnt1[N][26],cnt2[N][26];
int n;
string in1[maxn],in2[maxn];
mt19937_64 rnd(64);
void add(int x,int y,int w){
if(!g[x][y])return;
g[x][y]=g[y][x]=0;
frm[x][y]=frm[y][x]=w;
--deg2[x],--deg2[y];
}
vi res1[N];
map<string,int>mp1,mp2;
signed main()
{
// freopen("phase1.in","r",stdin);
cin>>opt;
if(opt[0]=='p'){
cin>>n;
For(i,1,n)cin>>in1[i];
}else{
cin>>n;
For(i,1,n)cin>>in1[i]>>in2[i];
}
cin>>n1;
For(i,1,n1)cin>>s1[i];
cin>>n2;
For(i,1,n2)cin>>s2[i];
For(i,1,n1) for(auto c:s1[i]) ++cnt1[i][c-'a'];
For(i,1,n2) for(auto c:s2[i]) ++cnt2[i][c-'a'];
int sums=0;
/// cerr<<"n1,n2 "<<n1<<" "<<n2<<"\n";
// cerr<<"n1n2 "<<n1*n2<<"\n";
For(i,1,n1) {
For(j,1,n2) {
ok[i][j]=1;
For(c,'a','z'){
if(cnt1[i][c-'a']<cnt2[j][c-'a']){
ok[i][j]=0;
break;
}
}
if(ok[i][j]){
++deg1[i];
++deg2[j];
e[i].pb(j);
++sums;
}
}
}
// cerr<<"sums "<<sums<<"\n";
For(i,1,n1) id1[i]=i;
sort(id1+1,id1+n1+1,[&](int x,int y){
return deg1[x]<deg1[y];
});
// For(i,1,n1)cout<<id1[i]<<" "<<deg1[id1[i]]<<" "<<s1[i]<<"\n";
memset(g,1,sizeof g);
For(i,1,n2) deg2[i]=n2;
For(ii,1,n1){
int i=id1[ii];
if(deg1[i]<3)continue;
// shuffle(e[i].begin(),e[i].end(),rnd);
sort(e[i].begin(),e[i].end(),[&](int x,int y){
return deg2[x]<deg2[y];
});
shuffle(e[i].begin(),e[i].end(),rnd);
auto find=[&](){
// cout<<"sz "<<e[i].size()<<"\n";
for(int x:e[i])
for(int y:e[i])if(y!=x && g[x][y])
for(int z:e[i])if(z!=x&&z!=y && g[x][z] && g[y][z]){
add(x,y,i);
add(x,z,i);
add(y,z,i);
res1[i]={x,y,z};
return;
}
for(int x:e[i])
for(int y:e[i])if(g[x][y])
for(int z:e[i])if(g[x][z] && g[y][z]){
add(x,y,i);
add(x,z,i);
add(y,z,i);
res1[i]={x,y,z};
return;
}
cerr<<"Fail "<<ii<<" "<<i<<"\n";
assert(0);
};
find();
}
For(i,1,n1) mp1[s1[i]]=i;
For(i,1,n2) mp2[s2[i]]=i;
if(opt[0]=='p'){
For(i,1,n){
int u=mp1[in1[i]];
int x=res1[u][0],y=res1[u][1],z=res1[u][2];
cout<<s2[x]<<" "<<s2[y]<<" "<<s2[z]<<endl;
}
}else{
For(i,1,n){
int x=mp2[in1[i]],y=mp2[in2[i]];
int u=g[x][y];
cout<<s1[u]<<endl;
}
}
return 0;
}
/*
encode
3
4
((((|)|)|)|)
5
(|(|))((|(|))|)
7 15 (kmax-n+4)
9 27
11 50-11
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 956ms
memory: 131068kb
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:
rods rasp proa etui ruth trio
input:
keys 4 rods rasp trio ruth proa rods rasp proa 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:
result:
wrong output format Unexpected end of file - token expected