Submission #1215094

#TimeUsernameProblemLanguageResultExecution timeMemory
1215094LM1Combo (IOI18_combo)C++20
100 / 100
6 ms484 KiB
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include<bits/stdc++.h>
#include "combo.h"
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define fr(i,ii,iii) for(int i=ii;i<iii;i++)
using namespace std;



//namespace {
//
//constexpr int MAX_N = 2000;
//constexpr int MAX_NUM_MOVES = 8000;
//
//int N;
//std::string S;
//
//int num_moves;
//
//void wrong_answer(const char *MSG) {
//  printf("Wrong Answer: %s\n", MSG);
//  exit(0);
//}
//
//}  // namespace
//
//int press(std::string p) {
//  if (++num_moves > MAX_NUM_MOVES) {
//    wrong_answer("too many moves");
//  }
//  int len = p.length();
//  if (len > 4 * N) {
//    wrong_answer("invalid press");
//  }
//  for (int i = 0; i < len; ++i) {
//    if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
//      wrong_answer("invalid press");
//    }
//  }
//  int coins = 0;
//  for (int i = 0, j = 0; i < len; ++i) {
//    if (j < N && S[j] == p[i]) {
//      ++j;
//    } else if (S[0] == p[i]) {
//      j = 1;
//    } else {
//      j = 0;
//    }
//    coins = std::max(coins, j);
//  }
//  return coins;
//}

string guess_sequence(int N){
	string ans="";
	int x;
	if(N==1){
		ans="A";
		x=press(ans);
		if(x==1)return ans;
		ans="B";
		x=press(ans);
		if(x==1)return ans;
		ans="X";
		x=press(ans);
		if(x==1)return ans;
		ans="Y";
		return ans;
	}
	x=press("AB");
	//cout<<x<<"\n";
	if(x==2){
		if(N==2)return ("AB");
	}
	if(x>=1){
		x=press("A");
		if(x==1){
			ans="A";
		}
		else ans="B";
	}
	else{
		x=press("X");
		if(x==1){
			ans="X";
		}
		else ans="Y";
	}
	string a;
	vector<char>v={'A','B','X','Y'};
	fr(i,0,4){
		if(v[i]==ans[0]){
			v.erase(v.begin()+i);
			break;
		}
	}
	//cout<<ans<<" "<<ans.size()<<"\n\n";
	fr(i,2,N){
		a=ans;
		a+=v[0];
		a+=ans;a+=v[1];a+=v[0];
		a+=ans;a+=v[1];a+=v[1];
		a+=ans;a+=v[1];a+=v[2];
		//cout<<a<<endl;
		x=press(a);
		if(x==ans.size()){
			ans+=v[2];
			continue;
		}
		if(x==ans.size()+1){
			ans+=v[0];
			continue;
		}
		if(x==ans.size()+2){
			ans+=v[1];
			continue;
		}
	}
	a=ans;
	a+=v[0];
	x=press(a);
	if(x==ans.size()+1){
		return a;
	}
	else{
		a=ans;
		a+=v[1];
		x=press(a);
		if(x==ans.size()+1){
			return a;
		}
		else{
			ans+=v[2];
			return ans;
		}
	}
}

//int main() {
//  char buffer[MAX_N + 1];
//  if (scanf("%s", buffer) != 1) {
//    fprintf(stderr, "Error while reading input\n");
//    exit(1);
//  }
//  S = buffer;
//  N = S.length();
//
//  num_moves = 0;
//  std::string answer = guess_sequence(N);
//  if (answer != S) {
//    wrong_answer("wrong guess");
//    exit(0);
//  }
//  printf("Accepted: %d\n", num_moves);
//  return 0;
//}
///*
//ABX
//*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...