Submission #316799

# Submission time Handle Problem Language Result Execution time Memory
316799 2020-10-28T04:38:27 Z seedkin Combo (IOI18_combo) C++11
0 / 100
1 ms 328 KB
#include "combo.h"

std::string guess_sequence(int N) {
  char map[200][3];
  map['A'][0] = 'B';
  map['A'][1] = 'X';
  map['A'][2] = 'Y';

  map['X'][0] = 'A';
  map['X'][1] = 'B';
  map['X'][2] = 'Y';

  map['B'][0] = 'A';
  map['B'][1] = 'X';
  map['B'][2] = 'Y';

  map['Y'][0] = 'A';
  map['Y'][1] = 'X';
  map['Y'][2] = 'B';

  std::string p = "";
  int coins;
  std::string S = "";
  char first;
  if(N == 1) {
    p = 'A';
    coins = press(p);
    if(coins) return p;
    p = 'B';
    coins = press(p);
    if(coins) return p;
    p = 'X';
    coins = press(p);
    if(coins) return p;
    p = 'Y';
    return p;
  } else if (N == 2) {
    p = "AAAB";
    coins = press(p);
    if(coins == 4) {
      S = "AB";
      return S;
    } else if (coins == 3) {
      S += 'A';
      first = 'A';
    } else if (coins == 1) {
      S += 'B';
      first = 'B';
    }

    p = "XXXY";
    coins = press(p);
    if(coins == 4) {
      S = "XY";
      return S;
    } else if (coins == 3) {
      S += 'X';
      first = 'X';
    } else if (coins == 1) {
      S += 'Y';
      first = 'Y';
    }

    p = S + map[first][0];
    p += S + map[first][1];
    p += S + map[first][1];

    coins = press(p);

    if(coins == 3) {
      S += map[first][2];
    } else if (coins == 4) {
      S += map[first][0];
    } else {
      S += map[first][1];
    }
    return S;
  } else {
    p = "AAAB";
    coins = press(p);
    if (coins >= 3) {
      S += 'A';
      first = 'A';
    } else if (coins == 1) {
      S += 'B';
      first = 'B';
    }

    p = "XXXY";
    coins = press(p);
    if (coins >= 3) {
      S += 'X';
      first = 'X';
    } else if (coins == 1) {
      S += 'Y';
      first = 'Y';
    }

    int len = 1;

    for(; len < N; len++) {
      p = S + map[first][0];
      p += S + map[first][1];
      p += S + map[first][1];

      coins = press(p);

      if(coins == len * 3) {
        S += map[first][2];
      } else if (coins == len * 3 + 1) {
        S += map[first][0];
      } else {
        S += map[first][1];
      }
    }
  }
  
  return S;
}

Compilation message

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:64:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   64 |     p = S + map[first][0];
      |                 ^~~~~
combo.cpp:65:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   65 |     p += S + map[first][1];
      |                  ^~~~~
combo.cpp:66:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   66 |     p += S + map[first][1];
      |                  ^~~~~
combo.cpp:71:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   71 |       S += map[first][2];
      |                ^~~~~
combo.cpp:73:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   73 |       S += map[first][0];
      |                ^~~~~
combo.cpp:75:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   75 |       S += map[first][1];
      |                ^~~~~
combo.cpp:102:19: warning: array subscript has type 'char' [-Wchar-subscripts]
  102 |       p = S + map[first][0];
      |                   ^~~~~
combo.cpp:103:20: warning: array subscript has type 'char' [-Wchar-subscripts]
  103 |       p += S + map[first][1];
      |                    ^~~~~
combo.cpp:104:20: warning: array subscript has type 'char' [-Wchar-subscripts]
  104 |       p += S + map[first][1];
      |                    ^~~~~
combo.cpp:109:18: warning: array subscript has type 'char' [-Wchar-subscripts]
  109 |         S += map[first][2];
      |                  ^~~~~
combo.cpp:111:18: warning: array subscript has type 'char' [-Wchar-subscripts]
  111 |         S += map[first][0];
      |                  ^~~~~
combo.cpp:113:18: warning: array subscript has type 'char' [-Wchar-subscripts]
  113 |         S += map[first][1];
      |                  ^~~~~
combo.cpp:102:19: warning: 'first' may be used uninitialized in this function [-Wmaybe-uninitialized]
  102 |       p = S + map[first][0];
      |                   ^~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 288 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Runtime error 1 ms 328 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -