Submission #939372

# Submission time Handle Problem Language Result Execution time Memory
939372 2024-03-06T10:06:46 Z ifateen Combo (IOI18_combo) C++14
0 / 100
1 ms 436 KB
#include <bits/stdc++.h>
#include "combo.h"
using namespace std;

string guess_sequence(int N) {
    string ans;
    vector<string> possible = {"A", "B", "X", "Y"};
    int a = press("A");
    if (a) {
        possible = {"B", "X", "Y", "A"};
        ans += 'A';
    } else {
        int b = press("B");
        if (b) {
            possible = {"A", "X", "Y", "B"};
            ans += 'B';
        } else {
            int x = press("X");
            if (x) {
                possible = {"A", "B", "Y", "X"};
                ans += 'X';
            } else {
                ans += 'Y';
            }
        }
    }
    while (ans.size() < N - 1) {
        string query;
        query += ans;
        query += possible[1];
        query += ans;
        query += possible[2];
        query += possible[0];
        query += ans;
        query += possible[2];
        query += possible[1];
        query += ans;
        query += possible[2];
        query += possible[2];
        int ret_value = press(query);
        if (ret_value == ans.size()) {
            // possible[0]
            ans += possible[0];
        } else if (ret_value == ans.size() + 1) {
            // possible[1]
            ans += possible[1];
        } else {
            assert(ret_value == ans.size() + 2);
            ans += possible[2];
        }
    }
    assert(possible[3][0] != ans.front());
    int zero = press(ans + possible[0]);
    if (zero == N) return ans + possible[0];
    int one = press(ans + possible[1]);
    if (one == N) return ans + possible[1];
    return ans + possible[2];
}

Compilation message

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:27:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     while (ans.size() < N - 1) {
      |            ~~~~~~~~~~~^~~~~~~
combo.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if (ret_value == ans.size()) {
      |             ~~~~~~~~~~^~~~~~~~~~~~~
combo.cpp:44:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         } else if (ret_value == ans.size() + 1) {
      |                    ~~~~~~~~~~^~~~~~~~~~~~~~~~~
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:48:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             assert(ret_value == ans.size() + 2);
      |                    ~~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 436 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 436 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -