Submission #441387

#TimeUsernameProblemLanguageResultExecution timeMemory
441387kymCombo (IOI18_combo)C++14
5 / 100
1 ms200 KiB
#include <bits/stdc++.h> using namespace std; //#define int ll #define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i) #define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i) #define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL #define db(x) cerr << #x << "=" << x << "\n" #define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n" #define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n" #define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n" #define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n" #define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n" #define reach cerr << "LINE: " << __LINE__ << "\n"; #else #define db(x) #define db2(x,y) #define db3(a,b,c) #define dbv(v) #define dbvp(v) #define dba(a,ss,ee) #define reach #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define ll long long #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define f first #define s second #define g0(x) get<0>(x) #define g1(x) get<1>(x) #define g2(x) get<2>(x) #define g3(x) get<3>(x) typedef pair <ll, ll> pi; typedef tuple<ll,ll,ll> ti3; typedef tuple<ll,ll,ll,ll> ti4; ll rand(ll a, ll b) { return a + rng() % (b-a+1); } const int MOD = 1e9 + 7; const int inf = (int)1e9 + 500; const long long oo = (ll)1e18 + 500; template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; } template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; } const int MAXN = -1; int press(std::string p); string guess_sequence(int N) { int x= press("AB"); char start; if(x==0){ int y=press("X"); if(y==1)start='X'; else start='Y'; } else { int y=press("A"); if(y==1)start='A'; else start='B'; } string choices; if(start!='A')choices.pb('A'); if(start!='B')choices.pb('B'); if(start!='X')choices.pb('X'); if(start!='Y')choices.pb('Y'); //db(choices); string ans; ans += start; FOR(i,2,N-1) { //db(ans); string now = ans; string s1=now+choices[0]+choices[0]; string s2=now+choices[0]+choices[1]; string s3=now+choices[0]+choices[2]; string s4=now+choices[1]; //db(s1+s2+s3+s4); int res = press(s1+s2+s3+s4); //db(res); if(res==(int)now.size()+2){ now+=choices[0]; } else if(res==(int)now.size()+1){ now+=choices[1]; } else { now+=choices[2]; } ans=now; } int r1=press(ans+choices[0]+ans+choices[1]); if(r1==(int)ans.size()+1) { r1=press(ans+choices[0]); if(r1==(int)ans.size()+1)ans+=choices[0]; else ans+=choices[1]; } else{ ans+=choices[2]; } return ans; } #ifdef LOCAL 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; } 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; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...