Submission #406007

#TimeUsernameProblemLanguageResultExecution timeMemory
406007sealnot123Combo (IOI18_combo)C++14
5 / 100
2 ms200 KiB
#include "combo.h"
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define ROF(i,a,b) for(int i=(a); i>=(b); --i)
#define pb push_back
#define eb emplace_back
#define SZ(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define make_unique(a) sort(all((a))), (a).erase(unique(all((a))),(a).end())
#define x first
#define y second
#define MP make_pair
#define MT make_tuple
#define debug(x) cout << #x << " = " << x << endl
#define debug2(x,y) FOR(i,1,y) cout << "##"; cout << #x << " = " << x << endl
#define mset(x) memset((x), 0, sizeof(x))

using namespace std;

typedef long long i64;
typedef tuple<int,int,int> iii;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

int readInt(){ int a; scanf("%d",&a); return a; }
i64 readLong(){ i64 a; scanf("%lld",&a); return a;}
void readString(char *s){ scanf(" %s",s); }

char A[]={'A','B','X','Y'};

string guess_sequence(int N) {
	string p = "";
	int res;
	// binary search
	if(press("AB") >= 1){
		if(press("B")) swap(A[0],A[1]); 
	}else{
		if(press("X")) swap(A[0],A[2]);
		else swap(A[0],A[3]);
	}
	p = A[0];
	// guess until N-1
	FOR(i, 2, N-1){
		string g = "";
		FOR(j,1,3) g+=p+A[1]+A[j];
		g+=p+A[2];
		int ans = press(g);
		if(ans == i+1) p += A[1];
		else if(ans == i) p += A[2];
		else p += A[3];
	}
	FOR(i, 1, 2){
		if(press(p+A[i])==N){
			p += A[i];
			break;
		}
	}
	if(p.size() != N) p+=A[3];
	return p;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:59:14: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |  if(p.size() != N) p+=A[3];
      |     ~~~~~~~~~^~~~
combo.cpp:34:6: warning: unused variable 'res' [-Wunused-variable]
   34 |  int res;
      |      ^~~
combo.cpp: In function 'int readInt()':
combo.cpp:26:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 | int readInt(){ int a; scanf("%d",&a); return a; }
      |                       ~~~~~^~~~~~~~~
combo.cpp: In function 'i64 readLong()':
combo.cpp:27:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 | i64 readLong(){ i64 a; scanf("%lld",&a); return a;}
      |                        ~~~~~^~~~~~~~~~~
combo.cpp: In function 'void readString(char*)':
combo.cpp:28:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 | void readString(char *s){ scanf(" %s",s); }
      |                           ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...