# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244223 | 2020-07-03T01:27:31 Z | MohamedAhmed04 | Password (RMI18_password) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std ; const int MAX = 1e5 + 10 ; int arr[MAX] , freq[27] , before[27][27] , letters[MAX] ; int n , c ; string ans = "" ; int query(string s); bool Check_Before(int a , int b) { string s = ans ; s.push_back((char)(a+'a')) ; for(int i = 0 ; i < freq[b] ; ++i) s.push_back((char)(b+'a')) ; return (query(s) == s.size()) ; } bool cmp(int &a , int &b) { return before[a][b] ; } string guess(int n , int c) { for(int i = 0 ; i < c ; ++i) freq[i] = Query(string(n , (char)('a'+i))) ; for(int i = 0 ; i < c ; ++i) { for(int j = i+1 ; j < c ; ++j) { before[i][j] = Check_Before(i , j) ; if(!before[i][j]) before[j][i] = 1 ; } } for(int i = 0 ; i < c ; ++i) letters[i] = i ; sort(letters , letters + c , cmp) ; for(int i = 0 ; i < n ; ++i) { int x = letters[0] ; freq[x]-- ; ans.push_back((char)(x+'a')) ; int l = 1 , r = c-1 ; int idx = 0 ; if(freq[x] == 0) idx = c-1 ; else { while(l <= r) { int mid = (l + r) >> 1 ; if(!Check_Before(letters[0] , letters[mid])) idx = mid , l = mid+1 ; else r = mid-1 ; } } for(int i = 0 ; i < idx ; ++i) letters[i] = letters[i+1] ; letters[idx] = x ; } return ans ; }