Submission #1052202

#TimeUsernameProblemLanguageResultExecution timeMemory
1052202khanhtbCombo (IOI18_combo)C++14
100 / 100
20 ms2004 KiB
#include <bits/stdc++.h>
#include "combo.h"
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7; 
const ll inf = 2e18;
const ll B = 320;
const ll N = 1e5+8;
vector<string> buttons = {"A","B","X","Y"};
string guess_sequence(int n) {
    int first_idx = -1; string ans = "";
    
    if (press(buttons[0] + buttons[1])) {
        if (press(buttons[0])) first_idx = 0;
        else first_idx = 1;
    }
    else {
        if (press(buttons[2])) first_idx = 2;
        else first_idx = 3;
    }
 
    assert(first_idx != -1);
    ans = buttons[first_idx];
 
    if (n == 1) return ans;
 
    int x = -1, y = -1, z = -1;
    for (int i = 0; i < 4; ++i) {
        if (i == first_idx) continue;
        if (x == -1) x = i;
        else if (y == -1) y = i;
        else z = i;
    }
 
    for (int i = 2; i < n; ++i) {
        string query = (ans + buttons[x]) + (ans + buttons[y] + buttons[x]) + (ans + buttons[y] + buttons[y]) + (ans + buttons[y] + buttons[z]);
        int query_ans = press(query);
        assert(ans.size() <= query_ans && query_ans <= ans.size() + 2);
        if (query_ans == ans.size() + 1) ans += buttons[x];
        else if (query_ans == ans.size() + 2) ans += buttons[y];
        else ans += buttons[z];
    }
 
    string query1 = ans + buttons[x], query2 = ans + buttons[y];
    if (press(query1) == n) return query1;
    if (press(query2) == n) return query2;
    return ans + buttons[z];
}

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from combo.cpp:1:
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:49:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         assert(ans.size() <= query_ans && query_ans <= ans.size() + 2);
      |                ~~~~~~~~~~~^~~~~~~~~~~~
combo.cpp:49:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         assert(ans.size() <= query_ans && query_ans <= ans.size() + 2);
      |                                           ~~~~~~~~~~^~~~~~~~~~~~~~~~~
combo.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if (query_ans == ans.size() + 1) ans += buttons[x];
      |             ~~~~~~~~~~^~~~~~~~~~~~~~~~~
combo.cpp:51:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         else if (query_ans == ans.size() + 2) ans += buttons[y];
      |                  ~~~~~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...