Submission #734682

#TimeUsernameProblemLanguageResultExecution timeMemory
734682rainliofficialCombo (IOI18_combo)C++11
Compilation error
0 ms0 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

/* 
Date: 2023/05/02 11:56
Problem Link: 
Topic(s):
Reflection:
Solution Notes:
We can obtain the first character in 2 moves:
guess AB
    if (>=1): then A or B
    else: then X or Y


Then we want to be able to determine 3 characters for every 1 query. 
Notice we get 4N queries, so it has something to do with 4 possibilities with every query. 

I initally didn't utilize the 4N constraint, and I thought about queries 2 new characters every time. 
If we have X, we query XAB: I hoped this would amortize to N queries. However, this would still end up
with the issue of having to determine > 2 possibilities with 1 query. 

Another key constraint is that the first character in S cannot appear again. We can thus use the first character, 
(e.g. X), to split differrent strings that we want to query. 

Consider the following method: 
X___ X___ X___ X___
What can we put in each of the empty spaces to for sure know the next character?  
XA XBA XBB XBC

If A is the next character -> return 1
If B is next char -> return 2
If Y is next character -> 0
*/

const int MAXN = 2e5+5, INF = 1e9;
int n;
vector<char> c = {'A', 'B', 'X', 'Y'}, cc;

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);
}

}  

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; 
    auto add1 = [&](){
        int x = press(s + "AB");
        if (x > sz(s)){
        // start with A
            if (press(s + 'A') > sz(s)) s += 'A';
            else s += "B";
        }else{
            if (press(s + 'X') > sz(s)) s += "X";
            else s += "Y";
        }
    };
    add1();
    for (char j : c) if (j != s[0]) cc.push_back(j);
    for (int i=1; i<n-1; i++){
        string q; 
        q += s + cc[0]; 
        for (int j=0; j<3; j++){
            q += s + cc[1] + cc[j];
        }
        int x = press(q);
        if (x == sz(s)) s += cc[2];
        else if (x == sz(s) + 1) s += cc[0];
        else if (x == sz(s) + 2) s += cc[1];
        else assert(false);
    }
    add1();
    return s;
}
// int main(){
//     // cin.tie(0); ios_base::sync_with_stdio(0);
//     // freopen("file.in", "r", stdin);
//     // freopen("file.out", "w", stdout);
//     S = "XABBABA";
//     N = sz(S);
//     num_moves = 0;
//     std::string answer = guess_sequence(N);
//     if (answer != S) {
//         cout << answer << "\n";
//         wrong_answer("wrong guess");
//         exit(0);
//     }
//     printf("Accepted: %d\n", num_moves);
// }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccWX1MIM.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/ccLnid8I.o:combo.cpp:(.text+0xf0): first defined here
collect2: error: ld returned 1 exit status