QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#601915#6401. Classic: N Real DNA Pots0x3ea#WA 0ms3540kbC++171.1kb2024-09-30 15:50:572024-09-30 15:50:58

Judging History

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

  • [2024-09-30 15:50:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3540kb
  • [2024-09-30 15:50:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    int rec = 0;
    auto q = [&](int x) -> int
    {
        cout << "? " << x << endl;
        int res;
        cin >> res;
        return res;
    };
    int l = 1, r = n, pre = 0;
    while (l < r)
    {
        int mid = (l + r + 1) >> 1;
        int rec = q(l);
        if (pre == rec)
        {
            cout << "! " << l << endl;
            return;
        }
        int res = q(mid);
        if (res == rec)
        {
            cout << "! " << mid << endl;
            return;
        }

        if (res == pre)
        {
            l = l + 1, r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
        pre = res;
        // cout << l << " " << r << endl;
    }
    cout << "! " << l << endl;
}
int main()
{
    // #ifdef x3ea
    //     freopen("in.txt", "r", stdin);
    //     freopen("out.txt", "w", stdout);
    // #endif
    //     ios::sync_with_stdio(false);
    //     cin.tie(0), cout.tie(0);
    int _ = 1;
    // cin >> _;
    while (_--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3540kb

input:

4 3
1 2
2 4
3 3
4 1

output:

? 1
? 3
! 4

result:

wrong output format Expected double, but "?" found