Submission #709225

# Submission time Handle Problem Language Result Execution time Memory
709225 2023-03-13T08:47:32 Z hmm789 Password (RMI18_password) C++14
30 / 100
621 ms 408 KB
#include <bits/stdc++.h>
using namespace std;
int query(string s);
string guess(int n, int s) {
	int cnt = 1;
	string ans = "";
	pair<int, int> occ[s];
	for(int i = 0; i < s; i++) {
		int l = 1, r = n+1;
		while(l < r) {
			int m = (l+r)/2;
			string s;
			
			for(int j = 0; j < m; j++) s += (char)('a'+i);
			//~ cout << "q" << cnt << ": " << s << endl;
			if(query(s) == m) l = m+1;
			else r = m;
		}
		occ[i].first = l-1;
		occ[i].second = i;
		//~ cout << "a " << i << " " << l-1 << endl;
	}
	sort(occ, occ+s);
	for(int i = 0; i < occ[0].first; i++) ans += (char)('a'+occ[0].second);
	for(int i = 1; i < s; i++) {
		//~ cout << "s" << i << ": " << ans << endl;
		int tmpcnt[ans.size()+1], sm = 0;
		memset(tmpcnt, 0, sizeof(tmpcnt));
		for(int j = ans.size(); j >= 0; j--) {
			int l = sm+1, r = occ[i].first+1;
			while(l < r) {
				int m = (l+r)/2;
				string tmp = "";
				for(int k = 0; k < j; k++) tmp += ans[k];
				for(int k = 0; k < m; k++) tmp += (char)('a'+occ[i].second);
				if(query(tmp) == tmp.size()) l = m+1;
				else r = m;
			}
			tmpcnt[j] = l-1-sm;
			sm += l-1-sm;
		}
		string tmp = "";
		for(int j = 0; j < ans.size(); j++) tmp += ans[j];
		//~ cout << "s" << i << ": " <<  tmp << endl;
		ans = "";
		for(int j = 0; j < tmpcnt[0]; j++) ans += (char)('a'+occ[i].second);
		for(int j = 1; j <= tmp.size(); j++) {
			//~ cout << "s" << i << "(" << j << "): " << ans << endl;
			ans += tmp[j-1];
			for(int k = 0; k < tmpcnt[j]; k++) ans += (char)('a'+occ[i].second);
		}
		//~ cout << "s" << i << ": " << ans << endl;
	}
	return ans;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     if(query(tmp) == tmp.size()) l = m+1;
      |        ~~~~~~~~~~~^~~~~~~~~~~~~
password.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int j = 0; j < ans.size(); j++) tmp += ans[j];
      |                  ~~^~~~~~~~~~~~
password.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int j = 1; j <= tmp.size(); j++) {
      |                  ~~^~~~~~~~~~~~~
password.cpp:5:6: warning: unused variable 'cnt' [-Wunused-variable]
    5 |  int cnt = 1;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 133 queries.
2 Correct 2 ms 208 KB Guessed the password with 249 queries.
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Guessed the password with 126 queries.
2 Correct 2 ms 208 KB Guessed the password with 142 queries.
3 Correct 2 ms 208 KB Guessed the password with 121 queries.
4 Correct 4 ms 208 KB Guessed the password with 374 queries.
# Verdict Execution time Memory Grader output
1 Correct 178 ms 312 KB Guessed the password with 13556 queries.
2 Correct 521 ms 408 KB Guessed the password with 45024 queries.
3 Correct 273 ms 320 KB Guessed the password with 25734 queries.
4 Incorrect 621 ms 320 KB Could not guess the password with 50000 queries.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 133 queries.
2 Correct 2 ms 208 KB Guessed the password with 249 queries.
3 Correct 2 ms 208 KB Guessed the password with 126 queries.
4 Correct 2 ms 208 KB Guessed the password with 142 queries.
5 Correct 2 ms 208 KB Guessed the password with 121 queries.
6 Correct 4 ms 208 KB Guessed the password with 374 queries.
7 Correct 178 ms 312 KB Guessed the password with 13556 queries.
8 Correct 521 ms 408 KB Guessed the password with 45024 queries.
9 Correct 273 ms 320 KB Guessed the password with 25734 queries.
10 Incorrect 621 ms 320 KB Could not guess the password with 50000 queries.
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 133 queries.
2 Correct 2 ms 208 KB Guessed the password with 249 queries.
3 Correct 2 ms 208 KB Guessed the password with 126 queries.
4 Correct 2 ms 208 KB Guessed the password with 142 queries.
5 Correct 2 ms 208 KB Guessed the password with 121 queries.
6 Correct 4 ms 208 KB Guessed the password with 374 queries.
7 Correct 178 ms 312 KB Guessed the password with 13556 queries.
8 Correct 521 ms 408 KB Guessed the password with 45024 queries.
9 Correct 273 ms 320 KB Guessed the password with 25734 queries.
10 Incorrect 621 ms 320 KB Could not guess the password with 50000 queries.
11 Halted 0 ms 0 KB -