QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322896#4828. Four Plus Fourbachbeo20070 596ms84380kbC++233.4kb2024-02-07 22:15:022024-02-07 22:15:03

Judging History

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

  • [2024-02-07 22:15:03]
  • 评测
  • 测评结果:0
  • 用时:596ms
  • 内存:84380kb
  • [2024-02-07 22:15:02]
  • 提交

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,rng);
    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;
        //cout << cnt << ' ' << id << endl;
        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_first();y<M;y=ny._Find_next(y)){
                    bitset<M> nz=ny&c[y];
                    for(int z=nz._Find_first();z<M;z=nz._Find_next(z)) 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;
    }
}
void encode(string s){
    int id=pass[s];
    //cout << id << ' ' << V[id][0] << ' ' << V[id][1] << ' ' << V[id][2] << '\n';
    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];
    cout << P[f[x][y]].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: 0
Wrong Answer
time: 596ms
memory: 84380kb

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:

saws drop woad
thou coir huic

input:

keys
4
saws drop
huic coir
woad saws
drop woad
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:

aardvark
aardvark
aardvark
aardvark

result:

wrong answer query 1: read aardvark but expected password