QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322905#4828. Four Plus Fourbachbeo20070 552ms88544kbC++233.6kb2024-02-07 22:35:522024-02-07 22:35:54

Judging History

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

  • [2024-02-07 22:35:54]
  • 评测
  • 测评结果:0
  • 用时:552ms
  • 内存:88544kb
  • [2024-02-07 22:35:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define mpp make_pair
#define fi first
#define se second

const int N=28558,M=3919;
int S[]={2,3,2,2,3,2,2,2,2,2,2,3,3,2,2,2,1,3,3,2,2,2,2,1,2,2};
struct Password{
    string s;
    ull mask=0;
    Password(){};
    Password(string ss):s(ss){
        vector<int> cnt(26);
        for(char c:s) cnt[c-'a']++;
        int total=0;
        for(int i=0;i<26;i++){
            mask+=((1ULL<<min(S[i],cnt[i]))-1)<<total;
            total+=S[i];
        }
    }
    int submask(Password P){
        return (mask&P.mask)==P.mask;
    }
    friend bool operator<(Password a,Password b){
        return a.s<b.s;
    }
};

int f[M][M];
Password P[N],K[M];
vector<int> V[N];
map<string,int> key,pass;
bitset<M> g[N],c[M];

void init(){
    int n;cin >> n;
    for(int i=0;i<N;i++){
        string s;cin >> s;
        P[i]=s;pass[s]=i;
    }
    int m;cin >> m;
    for(int i=0;i<M;i++){
        string s;cin >> s;
        K[i]=s;
    }
    shuffle(K,K+M,mt19937(9112001));
    for(int i=0;i<M;i++) key[K[i].s]=i;

    vector<pii> order(N);
    for(int i=0;i<N;i++){
        order[i].se=i;
        for(int j=0;j<M;j++){
            g[i][j]=P[i].submask(K[j]);
        }
        order[i].fi=g[i].count();
    }
    sort(order.begin(),order.end());
    for(int i=0;i<M;i++) c[i].set();
    for(auto [cnt,id]:order){
        if(cnt<3) continue;
        vector<int> res;
        function<vector<int>()> get = [&](){
            for(int x=g[id]._Find_first();x<M;x=g[id]._Find_next(x)){
                bitset<M> ny=g[id]&c[x];
                for(int y=ny._Find_next(x);y<M;y=ny._Find_next(y)){
                    if(!c[x][y]) continue;
                    bitset<M> nz=ny&c[y];
                    for(int z=ny._Find_next(y);z<M;z=nz._Find_next(z)){
                        if(!c[x][z] || !c[y][z]) continue;
                        return res={x,y,z};
                    }
                }
            }
            for(int x=g[id]._Find_first();x<M;x=g[id]._Find_next(x)){
                if(c[x][x]) return res={x,x,x};
            }
            return res={-1,-1,-1};
        };
        V[id]=get();
        int x=V[id][0],y=V[id][1],z=V[id][2];
        if(x==-1) continue;
        c[x][y]=c[x][z]=c[y][z]=c[y][x]=c[z][x]=c[z][y]=0;
        f[x][y]=f[x][z]=f[y][z]=f[y][x]=f[z][x]=f[z][y]=id+1;
    }
}
void encode(string s){
    int id=pass[s];
    //cout << id << ' ' << V[id][0] << ' ' << V[id][1] << ' ' << V[id][2] << '\n';
    assert(V[id][0]!=-1 && V[id][1]!=-1 && V[id][2]!=-1);
    cout << K[V[id][0]].s << ' ' << K[V[id][1]].s << ' ' << K[V[id][2]].s << '\n';
}
void decode(string a,string b){
    int x=key[a],y=key[b];
    assert(f[x][y]);
    cout << P[f[x][y]-1].s << '\n';
}

void solve(){
    string type;cin >> type;
    int n;cin >> n;
    vector<pair<string,string>> p(n);
    if(type=="password"){
        for(int i=0;i<n;i++) cin >> p[i].fi;
    }
    else{
        for(int i=0;i<n;i++) cin >> p[i].fi >> p[i].se;
    }
    init();
    if(type=="password"){
        for(int i=0;i<n;i++) encode(p[i].fi);
    }
    else{
        for(int i=0;i<n;i++) decode(p[i].fi,p[i].se);
    }
}

signed main(){
    //freopen("input.txt","r",stdin);
    //freopen("001.phase1.full.input","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 534ms
memory: 84604kb

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:

soda sows wars
euro chit otic

input:

keys
4
soda sows
otic chit
wars soda
sows wars
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: 526ms
memory: 84184kb

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:

ruer keir kier

input:

keys
1
keir kier
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: 552ms
memory: 84160kb

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:

dark kava vara
alar flow woad
dark kava vara

input:

keys
18
kava vara
dark vara
woad alar
dark kava
dark vara
vara kava
flow woad
alar flow
vara dark
woad flow
kava vara
alar woad
dark kava
vara kava
kava dark
flow alar
vara dark
kava dark
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: 100
Accepted
time: 550ms
memory: 88544kb

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:

dark kava vara
alar flow woad
loge vasa agas
sabs uses cubs
anal eons albs
area beer perm
soda abas ansa
bail pica pial
ayes abas lads
nigh abas bins
teal blet baba
seis bats bate
trot obit aria
abas asci sibb
bail tali blat
sabs sees base
caid beta tide
odea nobs mobs
maid bind iamb
beau scad nubs
...

input:

keys
60000
glia acne
lees heel
clit fets
nazi egos
once dine
grog frog
best rusk
diet dins
brie aide
sike kief
emir ergo
deem dens
sofa loaf
life flea
seis kerb
neat nude
elan nolo
ones rose
shad haed
flap lats
both beth
recs aces
dits rise
loge cols
odic fain
reis fils
dire seis
from form
vain gait...

output:

cleaning
fleeches
felsitic
agonizes
coincide
frogging
bruskest
dinkiest
arabized
forkiest
armigero
endosome
falloffs
fallible
briskest
denudate
canoodle
conquers
dashiest
flypasts
bioethic
carrells
dextrins
cloggers
fricando
filarees
dressier
formwork
aviating
dogeship
arousals
celestas
buttocks
epi...

result:

ok OK

Test #5:

score: 100
Accepted
time: 544ms
memory: 87908kb

input:

password
10000
fucoidal
fuddling
fuehrers
fuellers
fuelling
fuelwood
fugacity
fuggiest
fugitive
fugleman
fuglemen
fuguists
fulcrums
fulfills
fullback
fullered
fullface
fullness
fulmined
fulmines
fulminic
fumarase
fumarate
fumarole
fumatory
fumblers
fumbling
fumeless
fumelike
fumettes
fumigant
fumiga...

output:

laud coil fido
iglu guid fund
user fehs free
user fell fees
iglu fell neif
duel wood fool
yagi gait fact
eggs fets gits
five give gift
ulna alme menu
luge menu flee
fits tuis guts
surf sulu lums
fils lull flus
flak back fuck
duel fell rede
luce flea face
null feus ells
duel fine limn
mils feus muns
...

input:

keys
60000
iris neat
trot toit
horn lino
pond doer
orts toll
perk poor
poem dits
over brie
vrow doer
farl roam
emir kiva
outs inro
plum perm
nori rein
hays snap
naan twat
sink wonk
ires alee
ulna quay
lids seis
gyre gree
neat stoa
pure epic
rope outs
omit roti
boom mome
teal yare
seep umps
neat stum...

output:

inertias
hitherto
hornbill
proponed
pollster
pokeroot
imposted
overbill
overword
platform
maverick
outrings
plumbery
inventor
pansophy
nanowatt
knowings
realiser
quaintly
linseeds
greenery
notecase
pictured
posturer
milkwort
moonbeam
rectally
presumer
nutmeats
legality
hidrosis
panderer
haunches
ove...

result:

ok OK

Test #6:

score: 0
Stage 1: Program answer Runtime Error

input:

password
8488
redounds
redpolls
redrafts
redrawer
redreams
redreamt
redrills
redriven
redrives
redroots
redrying
redshank
redshift
redshirt
redskins
redstart
redtails
redubbed
reducers
reducing
reductor
reduviid
redwares
redwings
redwoods
redyeing
reearned
reechier
reechoed
reechoes
reedbird
reedbuc...

output:

doer sudd sure
doer lops peds
rats daft fade
draw rear were
mesa dear sard
meat deer dare
rids ells dill
veer dine rind
rids vees dive
doer orts teds
rynd dyne gird
dank hens rash
dits fret fish
dits heir edhs
seis rend dirk
rats sade read
dits lear lase
bree deed burd
used deer suer
rung cedi cued
...

input:


output:


result: