이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
string guess_sequence(int n){
int x = press("AB");
string s;
if (x >= 1){
// start with A
if (press("A")) s += 'A';
else s += "B";
}else{
if (press("X")) s += "X";
else s += "Y";
}
for (char j : c) if (j != s[0]) cc.push_back(j);
for (int i=1; i<n; i++){
string q;
q += s + cc[0];
for (int j=0; j<3; j++){
q += s + cc[1] + cc[j];
}
x = press(q);
if (x == sz(q)) s += cc[2];
else if (x == sz(q) + 1) s += cc[0];
else s += cc[1];
}
return s;
}
// int main(){
// cin.tie(0); ios_base::sync_with_stdio(0);
// freopen("file.in", "r", stdin);
// // freopen("file.out", "w", stdout);
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |