QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#858571#8939. PermutationMightZeroWA 1ms3584kbC++201.9kb2025-01-16 19:21:362025-01-16 19:21:37

Judging History

This is the latest submission verdict.

  • [2025-01-16 19:21:37]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3584kb
  • [2025-01-16 19:21:36]
  • Submitted

answer

#include<bits/stdc++.h>
#define loop(x,l,r) for(ll (x) = (l);(x)<=(r);++(x))
#define rloop(x,l,r) for(ll (x) = (r);(x)>=(l);--(x))
#define elif else if
using namespace std;
using ll = long long;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=ch-'0';ch=getchar();}
    return x*f;
}
inline void write(ll x)
{
    if(x<0){putchar('-');x=-x;}
    if(x%10==x){putchar(x+'0');return;}
    write(x/10);putchar(x%10+'0');
}
ll n,pos;
const double t=0.618;
void solve(ll l,ll r)
{
    if(l==r)
    {
        cout<<"! "<<l<<endl;
        return;
    }
    if(l==r-1)
    {
        if(pos==l)cout<<"! "<<r<<endl;
        else cout<<"! "<<l<<endl;
        return;
    }
    ll mid=t*l+(1-t)*r,np;
    if(pos<=mid)
    {
        if(l==mid)
        {
            solve(mid+1,r);
            return;
        }
        cout<<"? "<<l<<" "<<mid<<endl;
        cin>>np;
        if(np==pos)solve(l,mid);
        else
        {
            if(mid+1!=r)
            {
                cout<<"? "<<mid+1<<" "<<r<<endl;
                cin>>pos;
            }
            solve(mid+1,r);
        }
    }
    else
    {
        mid=t*r+(1-t)*l;
        if(r==mid+1)
        {
            solve(l,mid);
            return;
        }
        cout<<"? "<<mid+1<<" "<<r<<endl;
        cin>>np;
        if(np==pos)solve(mid+1,r);
        else
        {
            if(mid!=l)
            {
                cout<<"? "<<l<<" "<<mid<<endl;
                cin>>pos;
            }
            solve(l,mid);
        }
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    ll T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        cout<<"? "<<1<<" "<<n<<endl;
        cin>>pos;
        solve(1,n);
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3584kb

input:

3
5
3
5
2

output:

? 1 5
? 4 5
? 1 3
! 1

result:

wrong answer Wrong prediction (test case 1)