Submission #1285315

#TimeUsernameProblemLanguageResultExecution timeMemory
1285315ghammazhassanCombo (IOI18_combo)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
#include "combo.h"
using namespace std;
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){
  string s;
  int x;
  for (int i=0;i<1;i++){
    s="AB";
    x=press(s);
    if (x){
      s="A";
      x=press(s);
      if (x){
        s="A";
        break;
      }
      s="B";
      break;
    }
    s="X";
    x=press(s);
    if (x){
      break;
    }
    s="Y";
  }
  string o;
  if (s=="A"){
    o="BXY";
  }
  if (s=="B"){
    o="AXY";
  }
  if (s=="X"){
    o="ABY";
  }
  if (s=="Y"){
    o="ABX";
  }
  string p;
  while (s.size()<n-1){
    p=s+o[0]+s+o[1]+o[0]+s+o[1]+o[1]+s+o[1]+o[2];
    x=press(p);
    if (x==s.size()+1){
      s+=o[0];
    }
    else if(x==s.size()+2){
      s+=o[1];
    }
    else{
      s+=o[2];
    }
  }
  p=s+o[0];
  x=press(p);
  if (x==s.size()+1){
    s+=o[0];
  }
  else{
    p=s+o[1];
    x=press(p);
    if (x==s.size()+1){
      s+=o[1];
    }
    else{
      s+=o[2];
    }
  }
  return s;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cc1A1z8D.o: in function `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
grader.cpp:(.text+0x0): multiple definition of `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; /tmp/ccywEHk4.o:combo.cpp:(.text+0x190): first defined here
collect2: error: ld returned 1 exit status