Submission #101530

#TimeUsernameProblemLanguageResultExecution timeMemory
101530baluteshihCombo (IOI18_combo)C++14
100 / 100
52 ms576 KiB
#include "combo.h"
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define F first
#define S second
#define ET cout << "\n"
#define MP make_pair
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

char nxt(char c)
{
	if(c=='A') return 'B';
	if(c=='B') return 'X';
	if(c=='X') return 'Y';
	return 'A';
}

char swi(char beg,char c)
{
	c=nxt(c);
	if(c==beg) return nxt(c);
	return c;
}

string one_guess(string a,int N)
{
	int nw,tmp;
	while(a.size()<N) a.pb(a[1]);
	nw=press(a);
	while(nw<N)
	{
		for(int i=nw;i<N;++i)
			a[i]=swi(a[0],a[i]);
		tmp=press(a);
		if(tmp>nw) nw=tmp; 
		else a[nw]=swi(a[0],a[nw]),++nw;
	}
	return a;
}

string guess_sequence(int N)
{
	string b,c,d,beg;
	if(press("AB")!=0)
		if(press("A")==1) beg="A";
		else beg="B";
	else 
		if(press("X")==1) beg="X";
		else beg="Y";
	if(N==1) return beg; 
	b.pb(nxt(beg[0])),c.pb(nxt(b.back())),d.pb(nxt(c.back()));
	while(beg.size()+1<N)
	{
		int tmp=press(beg+b+b+beg+b+c+beg+b+d+beg+c);
		if(tmp==beg.size()) beg+=d;
		else if(tmp==beg.size()+1) beg+=c;
		else beg+=b;
	} 
	if(press(beg+b)==N) return beg+b;
	else if(press(beg+c)==N) return beg+c;
	return beg+d;
} 

Compilation message (stderr)

combo.cpp: In function 'std::string one_guess(std::string, int)':
combo.cpp:36:16: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |  while(a.size()<N) a.pb(a[1]);
      |        ~~~~~~~~^~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:60:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |  while(beg.size()+1<N)
      |        ~~~~~~~~~~~~^~
combo.cpp:63:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   if(tmp==beg.size()) beg+=d;
      |      ~~~^~~~~~~~~~~~
combo.cpp:64:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   else if(tmp==beg.size()+1) beg+=c;
      |           ~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...