Submission #553659

#TimeUsernameProblemLanguageResultExecution timeMemory
553659MadokaMagicaFanCombo (IOI18_combo)C++14
100 / 100
38 ms592 KiB
#include <bits/stdc++.h>
using namespace std;
int fc;

int press(std::string p);

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

char getc(int x){
    if (x >= fc)
        ++x;
    return ps[x];
}

string guess_sequence(int N){
    string s = "";

    // char 1
    if (press("AB")){
        if (press("A"))
            fc = 0;
        else
            fc = 1;
    } else {
        if (press("X"))
            fc = 2;
        else
            fc = 3;
    }

    s += ps[fc];

    if (N==1)
        return s;

    --N;

    while(--N){
        string q = s + getc(0) + 
            s + getc(1) + getc(0) +
            s + getc(1) + getc(1) +
            s + getc(1) + getc(2);

        int ans = press(q);

        if(ans == s.size())
            s += getc(2);
        else if(ans == s.size() + 1)
            s += getc(0);
        else
            s += getc(1);
    }

    if (press(s+getc(0)) == s.size() + 1)
        s += getc(0);
    else if (press(s+getc(1)) == s.size() + 1)
        s += getc(1);
    else
        s += getc(2);

    return s;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(ans == s.size())
      |            ~~~~^~~~~~~~~~~
combo.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         else if(ans == s.size() + 1)
      |                 ~~~~^~~~~~~~~~~~~~~
combo.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     if (press(s+getc(0)) == s.size() + 1)
      |         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
combo.cpp:56:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     else if (press(s+getc(1)) == s.size() + 1)
      |              ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...