QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397582#6394. Turn on the Lightryh7#WA 1ms3620kbC++17957b2024-04-24 13:37:182024-04-24 13:37:18

Judging History

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

  • [2024-04-24 13:37:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3620kb
  • [2024-04-24 13:37:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ull;
int n,val;
int main() {
    cin>>n;
    int left = 1 , right = n;
    cout << "? 1\n";
    cout.flush();
    int t;
    cin >> t;
    if (!t) {
        cout << "! 1\n";
        cout.flush();
        return 0;
    }
    val = t;
    left = 2;
    while(left < right){
        int mid = (left + right) >> 1;
        cout<<("? ")<<mid<<"\n";
        cout.flush();
       // s.insert(mid);
       //int t;
        cin>>t;
        if(t > val){
            left = mid + 1;
        }else if(t < val){
            right = mid - 1;
        }else if(t == val){
            cout<<"! "<<mid<<'\n';
            cout.flush();
            return 0;
        }
        val = t;

    }
    cout<<"! "<<left<<'\n';
    cout.flush();
    return 0;

    //return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3568kb

input:

3
1
2

output:

? 1
? 2
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
0
1
2

output:

? 1
? 6
? 3
? 4
! 5

result:

wrong answer Wrong answer, more than 1 possible light!