Submission #572580

#TimeUsernameProblemLanguageResultExecution timeMemory
572580MohammadAghilCombo (IOI18_combo)C++14
100 / 100
33 ms584 KiB
#include <iostream>
#include "combo.h"
#include <algorithm>
#include <functional>
#include <random>
#include <cmath>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <string>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <limits.h>
#include <tuple>
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("avx2")
 using namespace std;
  typedef long long ll;
   typedef pair<ll, ll> pp;
    //#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) x.begin(), x.end()
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                //void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name; *iss >>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
const ll mod = 1e9 + 7, maxn = 2e5 + 5, lg = 21, inf = ll(1e18) + 5;

//string s = "ABBBBXXYYXYBY";
//
//int press(string t){
//    per(i,sz(s)-1,0){
//        rep(j,0,sz(t)-i){
//            if(string(begin(s), begin(s)+i+1) == string(begin(t)+j, begin(t)+j+i+1)) return i + 1;
//        }
//    }
//    return 0;
//}

string guess_sequence(int n){
    string ans = "";
    vector<char> ch = {'A', 'B', 'X', 'Y'};
    int r = press("AB");
    if(r) {
        r = press("A");
        if(r) ans += 'A';
        else ans += 'B';
    } else{
        r = press("X");
        if(r) ans += 'X';
        else ans += 'Y';
    }
    ch.erase(find(all(ch), ans[0]));
    if(n == 1) return ans;
    while(sz(ans) < n-1){
        string ask = "";
        ask += ans + ch[0] + ch[0];
        ask += ans + ch[0] + ch[1];
        ask += ans + ch[0] + ch[2];
        ask += ans + ch[1];
        ans += ch[2-press(ask)+sz(ans)];
    }
    string ask = ans + ch[0] + ans + ch[1];
    if(press(ask) > sz(ans)){
        ask = ans + ch[0];
        if(press(ask) > sz(ans)) ans += ch[0];
        else ans += ch[1];
    }else ans += ch[2];
    return ans;
}

//int main(){
//    cin.tie(0) -> sync_with_stdio(0);
//    cout << guess_sequence(sz(s)) << endl;
//    return 0;
//}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...