QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574771#6394. Turn on the LightGammaRaysWA 1ms3656kbC++231.2kb2024-09-19 00:24:472024-09-19 00:24:47

Judging History

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

  • [2024-09-19 00:24:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2024-09-19 00:24:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int tag;
int n;
int L, R, LST;
void solve(int l,int r,int lst)
{
    if(tag==1)
    {
        return;
    }
    int mid,x,y;
    mid=(l+r)>>1;
    if (l + 1 < r) {

    } else {
        L = l;
        R = r;
        LST = lst;
        return;
    }
    
    cout<<"? "<<mid<<"\n";
    cout.flush();
    cin>>x;
    if(x==lst)
    {
        tag=1;
        cout<<"! "<<mid;
        cout.flush();
        return;
    }
    
    cout<<"? "<<r<<"\n";
    cout.flush();
    cin>>y;
    if(y==x)
    {
        tag=1;
        cout<<"! "<<r;
        cout.flush();
        return;
    }
    // cout<<x<<" "<<y<<endl;
    if(x<y)
    {
        solve(l,max(l,mid-1),y);
    }
    else
    {
        solve(min(r-1,mid+1),r-1,y);
    }
    return;
}

int main()
{
    int n;
    cin>>n;
    tag=0;
    solve(1,n,0);
    if (tag) return 0;
    int res;
    cout << L << ' ' << R << endl;
    cout << "? " << L << endl;
    cin >> res;
    if (res == LST) {
        cout<<"! "<< L;
        return 0;
    }
    LST = res;
    cout << "? " << L << endl;
    cin >> res;
    if (res == LST) {
        cout<<"! "<< R; 
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
1

output:

? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3656kb

input:

10
1
0
1
0

output:

? 5
? 10
? 7
? 9
8 8
? 8

result:

wrong answer Token parameter [name=type] equals to "8", doesn't correspond to pattern "?|!"