Submission #1007206

#TimeUsernameProblemLanguageResultExecution timeMemory
1007206andecaandeciCombo (IOI18_combo)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

string s,ans,coba;
int n;

string guess_sequence(int N) {
  n = N;
  return s;
}

int press (string p) {
  int i=0, j=0, ret=0;
  while (i < n && j < p.size()) {
    if (s[i] == p[j]) {
      i++;
      ret = max(i,ret);
    } else {
      if (i>0) j--;
      i = 0; 
    }
    j++;
  }
  return ret;
}

for (int i=1; i<=n; i++) {
  if (i == 1) {
    coba = "AB";
    int x = press(coba);
    if (x == 0) {
      coba = "X";
      int y = press(coba);
      if (y == 1) {
        ans+="X";
      } else {
        ans+="Y";
      }
    } else {
      coba = "A";
      int y = press(coba);
      if (y == 1) {
        ans+="A";
      } else {
        ans+="B";
      }
    }
  } else {
    coba = ans + "B" + ans + "XB" + ans + "XX" + ans + "XY";
    int x = press(coba);
    if (x == n) {
      break;
    }
    if (x == i) {
      ans += "B";
    } else if (x == i + 1) {
      ans += "X";
    } else {
      ans += "Y";
      if (i == n) {
        int y = press(ans);
      }
    }
  }
}

Compilation message (stderr)

combo.cpp: In function 'int press(std::string)':
combo.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   while (i < n && j < p.size()) {
      |                   ~~^~~~~~~~~~
combo.cpp: At global scope:
combo.cpp:27:1: error: expected unqualified-id before 'for'
   27 | for (int i=1; i<=n; i++) {
      | ^~~
combo.cpp:27:15: error: 'i' does not name a type
   27 | for (int i=1; i<=n; i++) {
      |               ^
combo.cpp:27:21: error: 'i' does not name a type
   27 | for (int i=1; i<=n; i++) {
      |                     ^