답안 #723722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723722 2023-04-14T08:22:00 Z Johann Colors (BOI20_colors) C++14
0 / 100
1 ms 208 KB
#include "bits/stdc++.h"
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()

vi queries;
vi ans;
int query(int i)
{
    queries.push_back(i);
    cout << "? " << i << endl;
    int a;
    cin >> a;
    ans.push_back(a);
    return a;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N;
    cin >> N;
    int maxPot = 0;
    while (1 << (maxPot + 1) < N - 1)
        ++maxPot;

    // was ist mit kleinen n?
    int tryLen = 0;
    int centerpiece = 1 << (maxPot - 1);
    for (int i = maxPot - 2; i >= 0; i -= 2)
        if ((1 << i) & (N - 1))
            centerpiece += 1 << i;
    ++centerpiece;

    query(centerpiece);
    tryLen = 1 << (maxPot - 1);
    int a = query(centerpiece + tryLen);

    if (!a)
        // have to get bigger
        tryLen = 1 << maxPot;
    else
        tryLen /= 2;

    int len = 0;
    for (; tryLen > 0; tryLen /= 2)
    {
        int nextTry;
        if (queries.back() < centerpiece)
            nextTry = queries.back() + len + tryLen;
        else
            nextTry = queries.back() - len - tryLen;
        if (nextTry < 1 || nextTry > N)
            continue;
        if (nextTry != centerpiece)
        {
            a = query(nextTry);
            if (!a)
                len += tryLen;
        }
        else
            len += tryLen;
    }
    int answer = abs(queries.back() - queries[sz(queries) - 2]);
    if (!ans.back())
        cout << answer + 1 << endl;
    else
        cout << answer << endl;

    return 0;
};
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Token parameter [name=cmd] equals to "4", doesn't correspond to pattern "[?=]"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Token parameter [name=cmd] equals to "4", doesn't correspond to pattern "[?=]"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Token parameter [name=cmd] equals to "4", doesn't correspond to pattern "[?=]"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Token parameter [name=cmd] equals to "4", doesn't correspond to pattern "[?=]"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Token parameter [name=cmd] equals to "4", doesn't correspond to pattern "[?=]"
2 Halted 0 ms 0 KB -