QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589491#6394. Turn on the Lightyumingsk#WA 1ms3720kbC++141.4kb2024-09-25 18:09:292024-09-25 18:09:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-25 18:09:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3720kb
  • [2024-09-25 18:09:29]
  • 提交

answer

#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";

using namespace std;
const int Mod = 998244353;
using ll = long long;
#define int long long

int print(int x)
{
    cout << "? " << x << endl;
    int c;
    cin >> c;
    return c;
}

void solve()
{
    int n;
    cin >> n;
    int lst = 0;
    int cur = 0;
    int l = 1;
    int r = n;
    while (1)
    {
        cur = print(l);
        if (cur == lst)
        {
            cout << "! " << l << endl;
            return;
        }
        l++;
        lst = cur;

        while (l <= r)
        {
            if (l == r)
            {
                cout << "! " << l << endl;
                return;
            }
            int mid = l + r >> 1;
            cur = print(mid);
            if (cur > lst)
            {
                l = mid + 1;
                lst = cur;
            }
            else if (cur == lst)
            {
                cout << "! " << mid << endl;
                return;
            }
            else
            {
                r = mid - 1;
                lst = cur;
            }
        }
    }
}
signed main()
{
    // IOS;
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3708kb

input:

3
1
2

output:

? 1
? 2
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3720kb

input:

10
1
0
1
2

output:

? 1
? 6
? 3
? 4
! 5

result:

wrong answer Wrong answer, more than 1 possible light!