Submission #1072926

#TimeUsernameProblemLanguageResultExecution timeMemory
1072926duckindogCombo (IOI18_combo)C++17
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>

#ifndef LOCAL
#include "combo.h"
#endif

#ifdef LOCAL
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;
}
#endif

using namespace std;
string guess_sequence(int n) {
  string ret;

  auto guess = [&]() { 
    int x = press(ret + "AB");
    if (x - ret.size()) {
      if (press(ret + "A") - ret.size()) ret += "A";
      else ret += "B";
    }
    else {
      if (press(ret + "X") - ret.size()) ret += "X";
      else ret += "Y";
    }
  };

  guess();
  string s;
  for (auto ch : "ABXY")
    if (string(1, ch) != ret) s.push_back(ch);

  while (ret.size() < n) { 
    if (ret.size() * 4 + 7 <= 4 * n) { 
      int x = press(ret + s[0] + s[0] + ret + s[0] + s[1] + ret + s[0] + s[2] + ret + s[1]);
      char nxt = (x == ret.size() ? s[2] : x == ret.size() + 1 ? s[1] : s[0]);
      ret += nxt;
    } else guess(); 
  }

  return ret;
}

#ifdef LOCAL
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;
}
#endif

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:74:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   74 |   while (ret.size() < n) {
      |          ~~~~~~~~~~~^~~
combo.cpp:75:28: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   75 |     if (ret.size() * 4 + 7 <= 4 * n) {
      |         ~~~~~~~~~~~~~~~~~~~^~~~~~~~
combo.cpp:77:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |       char nxt = (x == ret.size() ? s[2] : x == ret.size() + 1 ? s[1] : s[0]);
      |                   ~~^~~~~~~~~~~~~
combo.cpp:77:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |       char nxt = (x == ret.size() ? s[2] : x == ret.size() + 1 ? s[1] : s[0]);
      |                                            ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...