Submission #671004

#TimeUsernameProblemLanguageResultExecution timeMemory
671004ArixcrestCombo (IOI18_combo)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
 
using ll =  long long;
#define pi pair<int,int> 
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
const ll INF = -1;
const int mx = 1e5+5;
const int modulo =1e9+7;
mt19937 mt;
// int press(string p){
// 	cout<<p<<"\n";
// 	string s = "ABXYX";
// 	int mx = 0;
// 	rep(x,0,p.length()-s.length()){
// 		int cnt = 0;
// 		rep(y,0,s.length()){
// 			if(p[x+y]==s[y]){
// 				cnt++;
// 			}else{
// 				break;
// 			}
// 		}
// 		mx = max(mx,cnt);
// 	}
// 	return mx;
// }
std::string fillseq(string s,int sz){
	string temp = "";
	while(temp.size()<sz){
		temp+=s;
	}
	while(temp.size()>sz) temp.pop_back();
	return temp;
}
std::string guess_sequence(int n){
	n = 4*n;
	int mx = 0;
	string ans = "";
	int v;
	vector<char> vals = {'A','B','X','Y'};
	int cnt =0;
	while(mx!=n/4){
		cnt++;
		if(mx==0){
			string temp1 = fillseq("A",n/2);
			temp1+=fillseq("B",n/2);
			v = press(temp1);
			if(v>mx){
				temp1 = fillseq("A",n);
				v = press(temp1);
				if(v>mx){
					mx = v;
					ans+="A";
				}else{
					ans+="B";
				}
			}else{
				temp1 = fillseq("X",n);
				v = press(temp1);
				if(v>mx){
					mx = v;
					ans+='X';
				}else{
					mx = v;
					ans+="Y";
				}
			}
			for(auto it = vals.begin();it!=vals.end();it++){
				if(*it==ans.front()){
					vals.erase(it);
					break;
				}
			}
		}else{
			if(mx==n/4-1){
				string temp1 = ans+vals[0];
				while(temp1.size()<n) temp1+=(ans.front());
				v = press(temp1);
				if(v-mx==1){
					ans+=vals[0];
					break;
				}
				temp1 = ans+vals[1];
				while(temp1.size()<n) temp1+=(ans.front());
				v = press(temp1);
				if(v-mx==1){
					ans+=vals[1];
					break;
				}else{
					ans+=vals[2];
					break;
				}

			}
			else{
				string temp1 = ans+vals[0]+vals[0];
				temp1+=ans+vals[0]+vals[1];
				temp1+=ans+vals[0]+vals[2];
				temp1+=ans+vals[1];
				while(temp1.size()<n) temp1+=(ans.front());
				v = press(temp1);
				if(v-mx==2){
					ans+=vals[0];
				}else if(v-mx==1){
					ans+=vals[1];
				}else{
					ans+=(vals[2]);
				}
				mx++;
			}

		}
	}
	// cout<<cnt<<" "<<ans<<"\n";
	return ans;

}

Compilation message (stderr)

combo.cpp: In function 'std::string fillseq(std::string, int)':
combo.cpp:31:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |  while(temp.size()<sz){
      |        ~~~~~~~~~~~^~~
combo.cpp:34:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |  while(temp.size()>sz) temp.pop_back();
      |        ~~~~~~~~~~~^~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:49:8: error: 'press' was not declared in this scope
   49 |    v = press(temp1);
      |        ^~~~~
combo.cpp:79:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |     while(temp1.size()<n) temp1+=(ans.front());
      |           ~~~~~~~~~~~~^~
combo.cpp:80:9: error: 'press' was not declared in this scope
   80 |     v = press(temp1);
      |         ^~~~~
combo.cpp:86:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   86 |     while(temp1.size()<n) temp1+=(ans.front());
      |           ~~~~~~~~~~~~^~
combo.cpp:102:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |     while(temp1.size()<n) temp1+=(ans.front());
      |           ~~~~~~~~~~~~^~
combo.cpp:103:9: error: 'press' was not declared in this scope
  103 |     v = press(temp1);
      |         ^~~~~