Submission #565949

#TimeUsernameProblemLanguageResultExecution timeMemory
565949hoanghq2004Combo (IOI18_combo)C++14
100 / 100
29 ms640 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "combo.h"

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;


//namespace {
//
//constexpr int MAX_N = 2000;
//constexpr int MAX_NUM_MOVES = 8000;
//
//int N;
//std::string S;
//
//int num_moves;
//
//void wrong_answer(const char *MSG) {
//  printf("Wrong Answer: %s\n", MSG);
//  exit(0);
//}
//
//}  // namespace
//
//int press(std::string p) {
//  if (++num_moves > MAX_NUM_MOVES) {
//    wrong_answer("too many moves");
//  }
//  int len = p.length();
//  if (len > 4 * N) {
//    wrong_answer("invalid press");
//  }
//  for (int i = 0; i < len; ++i) {
//    if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
//      wrong_answer("invalid press");
//    }
//  }
//  int coins = 0;
//  for (int i = 0, j = 0; i < len; ++i) {
//    if (j < N && S[j] == p[i]) {
//      ++j;
//    } else if (S[0] == p[i]) {
//      j = 1;
//    } else {
//      j = 0;
//    }
//    coins = std::max(coins, j);
//  }
//  return coins;
//}

string guess_sequence(int N) {
    char bg;
    string button;
    string s;
    if (press("AB")) {
        if (press("A")) button = "BXY", s = "A";
        else button = "AXY", s = "B";
    } else {
        if (press("X")) button = "ABY", s = "X";
        else button = "ABX", s = "Y";
    }
    for (int i = 1; i < N; ++i) {
        if (i + 1 < N) {
            string ask = s + button[0] + button[0] + s + button[0] + button[1] + s + button[0] + button[2] + s + button[1];
            int _ = press(ask);
            if (_ == i) s.push_back(button[2]);
            if (_ == i + 1) s.push_back(button[1]);
            if (_ == i + 2) s.push_back(button[0]);
        } else {
            string ask = s + button[0];
            if (press(ask) == N) s.push_back(button[0]);
            else {
                ask = s + button[1];
                if (press(ask) == N) s.push_back(button[1]);
                else s.push_back(button[2]);
            }
        }
    }
    return s;
}

//
//int main() {
//  char buffer[MAX_N + 1];
//  if (scanf("%s", buffer) != 1) {
//    fprintf(stderr, "Error while reading input\n");
//    exit(1);
//  }
//  S = buffer;
//  N = S.length();
//
//  num_moves = 0;
//  std::string answer = guess_sequence(N);
//  if (answer != S) {
//    wrong_answer("wrong guess");
//    exit(0);
//  }
//  printf("Accepted: %d\n", num_moves);
//  return 0;
//}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:60:10: warning: unused variable 'bg' [-Wunused-variable]
   60 |     char bg;
      |          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...