Submission #1091239

# Submission time Handle Problem Language Result Execution time Memory
1091239 2024-09-20T08:22:17 Z andrei_iorgulescu Colors (BOI20_colors) C++14
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int n;

int getx()
{
    int st = 0, pas = 1ll << 60;
    while (pas != 0)
    {
        if (st + pas <= n)
        {
            int x = st + pas;
            bool oops = false;
            int l = 1, r = n, pass = -1;
            while (l < r)
            {
                int y;
                pass++;
                int rn = (r - l) / 2;
                if (pass % 2 == 0)
                    y = x + l + rn;
                else
                    y = x - l - rn;
                if (y > n)
                    oops = true;
                l = abs(x - y) + 1;
                x = y;
            }
            if (!oops)
                st += pas;
        }
        pas /= 2;
    }
    return st;
}

signed main()
{
    cin >> n;
    int x = getx();
    cout << "? " << x << endl;
    int rsp;
    cin >> rsp;
    int l = 1, r = n;
    int pas = -1;
    while (l < r)
    {
        int y;
        pas++;
        ///eu legit caut binar cu l si r, in ce hal am ajuns
        int rn = (r - l) / 2;
        if (pas % 2 == 0)
            y = x + l + rn;
        else
            y = x - l - rn;
        y = max(y, 0ll);
        y = min(y, n);
        cout << "? " << y << endl;
        if (y <= 0)
            assert(false);
        if (y > n)
            while(true);
        cin >> rsp;
        if (rsp == 0)
            l = abs(x - y) + 1;
        else
            r = abs(x - y);
        x = y;
    }
    cout << "= " << l << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Hair color 7 was used multiple times
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Hair color 7 was used multiple times
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Hair color 7 was used multiple times
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Hair color 7 was used multiple times
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Hair color 7 was used multiple times
2 Halted 0 ms 0 KB -