Submission #349109

# Submission time Handle Problem Language Result Execution time Memory
349109 2021-01-16T17:29:46 Z spike1236 Combo (IOI18_combo) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
///#include "combo.h"
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define sz(_v) (int)_v.size()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

string ANS;
int N;
int cnt;

int press(string s) {
    ++cnt;
    string cur = s;
    int ans = 0;
    for(int len = sz(s); len > 0; --len) {
        for(int j = 0; j + len - 1 < N; ++j) {
            string t = "";
            for(int l = j; l <= j + len - 1; ++l) t += ANS[l];
            if(t == cur) return len;
        }
        cur.pop_back();
    }
    return 0;
}

bool check(char x) {
    string s = "";
    s += x;
    int cnt = press(s);
    if(cnt > 1 || !cnt) return 0;
    return 1;
}

string guess_sequence(int n) {
    string cur = "";
    set <char> st;
    st.insert('A');
    st.insert('B');
    st.insert('X');
    st.insert('Y');
    if(check('A')) cur = "A", st.erase('A');
    else if(check('B')) cur = "B", st.erase('B');
    else if(check('X')) cur = "X", st.erase('X');
    else cur = "Y", st.erase('Y');
    auto it = st.begin();
    char a1 = *it;
    ++it;
    char a2 = *it;
    ++it;
    char a3 = *it;
    for(int i = 1; i < n; ++i) {
        if(press(cur + a1) == i) {
            if(press(cur + a2) == i) {
                cur += a3;
                continue;
            }
            cur += a2;
            continue;
        }
        cur += a1;
    }
    return cur;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ANS = "ABXYYYYXX";
	N = sz(ANS);
	string answer = guess_sequence(N);
	if(ANS != answer)
        cout << "OH NO!\n" << ANS << ' ' << answer;
	else
        cout << "OK queries=" << cnt << ' ' << answer;
    return 0;
}

Compilation message

combo.cpp: In function 'int press(std::string)':
combo.cpp:31:9: warning: unused variable 'ans' [-Wunused-variable]
   31 |     int ans = 0;
      |         ^~~
/usr/bin/ld: /tmp/ccFcKPPT.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/cc1HxJeU.o:combo.cpp:(.text+0x4a0): first defined here
/usr/bin/ld: /tmp/ccFcKPPT.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc1HxJeU.o:combo.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status