QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323736 | #4828. Four Plus Four | hotboy2703 | 0 | 0ms | 0kb | C++14 | 3.7kb | 2024-02-10 13:04:05 | 2024-02-10 13:04:06 |
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL << (i))
vector <string> s8;
vector <string> s4;
ll n8,n4;
vector <ll> g[30010];
vector <ll> ans[30010];
vector <ll> subsets;
ll ap[4010][4010];
ll fi(string s,vector <string> &a){
return lower_bound(a.begin(),a.end(),s)-a.begin();
}
void generate_dictionary(){
for (ll mask = 0;mask < MASK(8);mask++)if (__builtin_popcount(mask)==4)subsets.push_back(mask);
memset(ap,-1,sizeof ap);
cin>>n8;
for (ll i = 0;i < n8;i ++){
string s;
cin>>s;
s8.push_back(s);
}
cin>>n4;
map <string,vector <ll> > mask_ids;
for (ll i = 0;i < n4;i ++){
string s;
cin>>s;
s4.push_back(s);
sort(s.begin(),s.end());
mask_ids[s].push_back(i);
}
for (ll i = 0;i < n8;i ++){
for (auto mask:subsets){
string tmp;
for (ll j = 0;j < 8;j ++){
if (BIT(mask,j))tmp.push_back(s8[i][j]);
}
sort(tmp.begin(),tmp.end());
g[i].insert(g[i].end(),mask_ids[tmp].begin(),mask_ids[tmp].end());
}
sort(g[i].begin(),g[i].end());
g[i].resize(unique(g[i].begin(),g[i].end())-g[i].begin());
}
vector <ll> order(n8);
iota(order.begin(),order.end(),0);
sort(order.begin(),order.end(),[&](ll x,ll y){return sz(g[x])<sz(g[y]);});
for (auto x:order){
if (sz(g[x])>=3){
ll x1,x2,x3;
for (ll i1 = 0;ans[x].empty() && i1 < sz(g[x]);i1++){
x1 = g[x][i1];
for (ll i2 = i1+1;ans[x].empty() && i2 < sz(g[x]);i2++){
x2 = g[x][i2];
if (ap[x1][x2]!=-1)continue;
for (ll i3 = i2+1;ans[x].empty() && i3 < sz(g[x]);i3++){
x3 = g[x][i3];
if (ap[x1][x3]==-1 && ap[x2][x3]==-1){
ap[x1][x2]=ap[x1][x3]=ap[x2][x1]=ap[x2][x3]=ap[x3][x1]=ap[x3][x2]=x;
ans[x] = {x1,x2,x3};
}
}
}
}
if(ans[x].empty()){
cout<<s8[x]<<' '<<sz(g[x])<<'\n';
exit(0);
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
string task;
cin>>task;
if (task=="password"){
ll n;
cin>>n;
vector <string> all;
for (ll i = 1;i <= n;i ++){
string s;
cin>>s;
all.push_back(s);
}
generate_dictionary();
for (auto x:all){
ll id_x = fi(x,s8);
// cout<<x<<' ';
for (auto y:ans[id_x]){
cout<<s4[y]<<' ';
}
cout<<'\n';
}
}
else{
ll n;
cin>>n;
vector <pair <string,string> > all;
for (ll i = 1;i <= n;i ++){
string s1,s2;
cin>>s1>>s2;
all.push_back({s1,s2});
}
generate_dictionary();
for (auto x:all){
pll id_x = {fi(x.fi,s4),fi(x.se,s4)};
cout<<s8[ap[id_x.fi][id_x.se]]<<'\n';
}
}
}
/*
password
2
password
couthier
2
couthier password
6
ctie hier road saws swap thou
keys
4
swap road
thou ctie
saws swap
road saws
2
couthier password
6
ctie hier road saws swap thou
road saws swap
ctie hier thou
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer on the first run
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:
henequin 3
input:
output:
result:
wrong output format Unexpected end of file - token expected