# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119122 | somefolk | Password (RMI18_password) | C++17 | 75 ms | 880 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <complex>
#include <list>
#include <chrono>
#include <random>
#include <stack>
#include <iomanip>
#include <fstream>
#include <cassert>
using namespace std;
#define endl "\n"
// #define int long long
const int INF = 2 * 1e5 + 5;
const int MOD = 1e9 + 7;
// int query(string s){
// int n;
// cout << s;
// cin >> n;
// return n;
// }
int query(string s);
string guess(int n, int s){
vector<char> a;
unordered_map<char, int> mp;
unordered_map<char, char> adj;
for(char i = 'a'; i < 'a'+s; i++){
int amount = query(string(n, i));
if(amount != 0){
a.push_back(i);
mp[i] = amount;
}
}
string sol = "";
for(int i = 0; i < n; i++){
// randomize:
random_device rd;
mt19937 g(rd());
shuffle(a.begin(), a.end(), g);
// for(auto &i : a){
// cout << i << " ";
// }
// cout << endl;
// get edeges between letters:
if(i == 0 || a.size() > 1){
char prev = a[0];
for(auto &j : a){
if(prev == j) continue;
if(query(sol + j + string(mp[prev], prev)) == sol.size() + mp[prev] + 1){
adj[prev] = j;
prev = j;
} else {
adj[j] = prev;
}
}
}
// for(auto &i : adj){
// cout << i.second << "<-" << i.first << endl;
// }
// dfs for last
char end = a[0];
while(true){
if(adj.count(end) == 0) break;
end = adj[end];
}
sol+=end;
mp[end]--;
// cout << end << endl;
// erase last and all edges to last
vector<char> dis;
if(mp[end]) dis.push_back(end);
for(auto it = adj.begin(); it != adj.end();){
if(it->second == end){
dis.push_back(it->first);
it = adj.erase(it);
} else {
it++;
}
}
// cout << endl;
// for(auto &i : adj){
// cout << i.second << "<-" << i.first << endl;
// }
a.clear();
a = dis;
}
return sol;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |