# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
755863 | 2023-06-10T16:58:43 Z | vjudge1 | Password (RMI18_password) | C++17 | 495 ms | 284 KB |
#include <bits/stdc++.h> #include <fstream> #include <iostream> #include <sstream> #include <string> #include <stdlib.h> #include <assert.h> #include <bits/stdc++.h> using namespace std; #define DEBUG 0 #define MAX_QUERIES 50000 #define MAX_N 5000 #define MAX_SIGMA 26 static string password; static int n, s, numQueries; static stringstream msg; /*static void end(int success) { cout << (success ? "SUCCESS! " : "ERROR: ") << msg.str() << endl; exit(0); } int query(string q) { if (++numQueries > MAX_QUERIES) { msg << "Could not guess the password with " << MAX_QUERIES << " questions."; end(0); } int len = q.size(); // validation if (len < 1 || len > n) { msg << "Query '" << q << "' should have length between 1 and " << n << " characters."; end(0); } for (int i = 0; i < len; i++) { if (q[i] < 'a' || q[i] >= 'a' + s) { msg << "Illegal character '" << q[i] << "' found."; end(0); } } // while possible, advance one character in q and find its next // occurrence in password int i = 0, j = 0, plen = password.size(); while (i < plen && j < len) { while ((i < plen) && (password[i] != q[j])) { i++; } if (i < plen) { found a match i++; j++; } } if (DEBUG) { cout << "Question #" << numQueries << " [" << q << "] answer " << j << endl; } return j; }*/ int query(string q); string guess(int n, int s){ int tab[s]; //cout <<n<<" "<<s<<endl; for (int i = 0; i < s; ++i) { char x=char(i+'a'); string t=""; for (int i = 0; i < n; ++i) { t.push_back(x); } int o=query(t); tab[i]=o; } int fir=0; int mx=0; for (int i = 0; i < s; ++i) { if (mx<tab[i]){ mx=tab[i]; fir=i; } } string res=""; for (int i = 0; i < tab[fir]; ++i) { char x=char(fir+'a'); res.push_back(x); } for (int i = 0; i < s; ++i) { if (i==fir) continue; for (int j = 0; j < tab[i]; ++j) { int p=res.size(); bool test=false; for (int k = 0; k < p+1; ++k) { if(test) continue; char x=char(i+'a'); string cur=""; //cout << x<<endl; for (int i = 0; i <= p; ++i) { if (i==k) cur.push_back(x); if (i==p) continue; cur.push_back(res[i]); }//cout << cur<<" "<<res<<endl; int c=query(cur); if (c>p){ res=cur; test=true; } } } }cout << res<<endl; return res; } /*int main() { /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ifstream f("password.in"); cin >> n >> s >> password; f.close(); assert(n && s && !password.empty()); string answer = guess(n, s); if (DEBUG) { cout << "Your answer: [" << answer << "]\n"; } if (answer.compare(password)) { msg << "Your answer was [" << answer << "] which does not match the password [" << password << "]."; end(0); } else { msg << "You guessed the password with " << numQueries << " queries."; end(1); } return 0; }*/
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 208 KB | Guessed the password with 76 queries. |
2 | Correct | 3 ms | 208 KB | Guessed the password with 187 queries. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 208 KB | Guessed the password with 759 queries. |
2 | Correct | 7 ms | 208 KB | Guessed the password with 716 queries. |
3 | Correct | 6 ms | 208 KB | Guessed the password with 971 queries. |
4 | Correct | 23 ms | 208 KB | Guessed the password with 2092 queries. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 495 ms | 284 KB | Could not guess the password with 50000 queries. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 208 KB | Guessed the password with 76 queries. |
2 | Correct | 3 ms | 208 KB | Guessed the password with 187 queries. |
3 | Correct | 7 ms | 208 KB | Guessed the password with 759 queries. |
4 | Correct | 7 ms | 208 KB | Guessed the password with 716 queries. |
5 | Correct | 6 ms | 208 KB | Guessed the password with 971 queries. |
6 | Correct | 23 ms | 208 KB | Guessed the password with 2092 queries. |
7 | Incorrect | 495 ms | 284 KB | Could not guess the password with 50000 queries. |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 208 KB | Guessed the password with 76 queries. |
2 | Correct | 3 ms | 208 KB | Guessed the password with 187 queries. |
3 | Correct | 7 ms | 208 KB | Guessed the password with 759 queries. |
4 | Correct | 7 ms | 208 KB | Guessed the password with 716 queries. |
5 | Correct | 6 ms | 208 KB | Guessed the password with 971 queries. |
6 | Correct | 23 ms | 208 KB | Guessed the password with 2092 queries. |
7 | Incorrect | 495 ms | 284 KB | Could not guess the password with 50000 queries. |
8 | Halted | 0 ms | 0 KB | - |