Submission #433766

# Submission time Handle Problem Language Result Execution time Memory
433766 2021-06-20T10:34:22 Z AmineWeslati Password (RMI18_password) C++14
30 / 100
299 ms 316 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

typedef string str; 

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)


void ckmin(int &x, int y){x=min(x,y);}
//------------------------------------

int query(string S);

int alp;

void upd(str &s, int idx, char c){
    str ss;
    FOR(i,0,sz(s)+1){
        if(i==idx) ss+=c;
        if(i<sz(s)) ss+=s[i];
    }
    s=ss; 
}

bool check(str s, int idx, char c){
    str ss; 
    FOR(i,0,min(idx,sz(s))) ss+=s[i];
    ss+=c; 

    FOR(i,idx,sz(s)) if(s[i]==c) ss+=s[i];

    return query(ss)==sz(ss);
}

str guess(int N, int S){
    alp=S; 
    vi nb(alp,0);
    for(char c='a'; c<=char('a'+alp-1); c++){
        str s;
        FOR(i,0,N) s+=c; 
        nb[c-'a']=query(s);
    }

     
    int idx=0;
    FOR(i,0,alp) if(nb[i]>nb[idx]) idx=i; 

    if(idx<0 || idx>=S) return ".";

    str cur;
    FOR(i,0,nb[idx]) cur+=char(idx+'a');

    FOR(i,0,alp) if(i!=idx){
        char c=i+'a';
        while(nb[i]--){
            int l=0,r=sz(cur),ind=-1;
            while(l<=r){
                int m=(l+r)/2;
                if(check(cur,m,c)){
                    ind=m; 
                    l=m+1;
                }
                else r=m-1;
            }
            if(ind==-1){
            	return ".";
            }

            upd(cur,ind,c);

            //cout << cur << endl;
        }
    }
    //cout << sz(cur) << endl;
    return cur; 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Guessed the password with 60 queries.
2 Correct 2 ms 200 KB Guessed the password with 101 queries.
# Verdict Execution time Memory Grader output
1 Correct 4 ms 200 KB Guessed the password with 130 queries.
2 Correct 2 ms 200 KB Guessed the password with 136 queries.
3 Runtime error 4 ms 200 KB Execution killed with signal 13
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 200 KB Guessed the password with 7127 queries.
2 Correct 177 ms 272 KB Guessed the password with 11156 queries.
3 Correct 210 ms 292 KB Guessed the password with 12222 queries.
4 Correct 299 ms 316 KB Guessed the password with 17912 queries.
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Guessed the password with 60 queries.
2 Correct 2 ms 200 KB Guessed the password with 101 queries.
3 Correct 4 ms 200 KB Guessed the password with 130 queries.
4 Correct 2 ms 200 KB Guessed the password with 136 queries.
5 Runtime error 4 ms 200 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Guessed the password with 60 queries.
2 Correct 2 ms 200 KB Guessed the password with 101 queries.
3 Correct 4 ms 200 KB Guessed the password with 130 queries.
4 Correct 2 ms 200 KB Guessed the password with 136 queries.
5 Runtime error 4 ms 200 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -