Submission #393698

#TimeUsernameProblemLanguageResultExecution timeMemory
393698teehandsomeCombo (IOI18_combo)C++11
97 / 100
56 ms608 KiB
#include "combo.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

char ar[4]={'A','B','X','Y'};
vector<char> ar2;

std::string guess_sequence(int N) {
    string ans="";
    char first='-';
    for(int i=0;i<3;i++) {
        ans.push_back(ar[i]);
        int temp=press(ans);
        if(temp==1) {
            first=ar[i]; break;
        }
        ans.pop_back();
    }
    if(first=='-') {
        first='Y'; ans.push_back(first);
    }
    for(int i=0;i<4;i++) {
        if(ar[i]!=first) ar2.push_back(ar[i]);
    }
    if(N==1) return ans;
    for(int i=1;i<N-1;i++) {
        string cur=ans;
        string temp="";
        for(int j=0;j<3;j++) {
            temp+=cur;
            temp.push_back(ar2[0]);
            temp.push_back(ar2[j]);
        }
        temp+=cur;
        temp.push_back(ar2[1]);
        int res=press(temp);
        if(res>=ans.size()+2) {
            ans.push_back(ar2[0]);
        }
        else if(res==ans.size()+1) {
            ans.push_back(ar2[1]);
        }
        else ans.push_back(ar2[2]);
    }
//    assert(ans.size()==N-1);
    for(int i=0;i<2;i++) {
        string temp=ans;
        temp.push_back(ar2[i]);
        int res=press(temp);
        if(res==N) {
            ans.push_back(ar2[i]); break;
        }
    }
    if(ans.size()==N-1) ans.push_back(ar2[2]);
    return ans;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         if(res>=ans.size()+2) {
      |            ~~~^~~~~~~~~~~~~~
combo.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         else if(res==ans.size()+1) {
      |                 ~~~^~~~~~~~~~~~~~
combo.cpp:82:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   82 |     if(ans.size()==N-1) ans.push_back(ar2[2]);
      |        ~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...