QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882940#9734. Identify ChordhuangkaichengWA 2ms3840kbC++142.5kb2025-02-05 13:42:412025-02-05 13:42:41

Judging History

This is the latest submission verdict.

  • [2025-02-05 13:42:41]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3840kb
  • [2025-02-05 13:42:41]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n;
int dis(int x,int y){return min(abs(x-y),n-abs(x-y));}
int tiao(int x,int delta)
{
    if (x+delta<=0) return x+delta+n;
    if (x+delta>n)  return x+delta-n;
    return x+delta;
}
void solve()
{
    scanf("%d",&n);
    int qi=1,zhong=n/2+1,ju_qi_zhong;
    while (1)
    {
        printf("? %d %d",qi,zhong);cout<<endl;
        scanf("%d",&ju_qi_zhong);
        if (ju_qi_zhong<n/2)    break;
        if (n&1)
        {
            if((zhong&1)==((n/2+1)&1))      zhong++;
            else                            qi++;
        }
        else                                qi++,zhong++;
    }
    int cha=dis(qi,zhong)-ju_qi_zhong;
    int zheng,fu;
    printf("? %d %d",qi%n+1,zhong);cout<<endl;
    scanf("%d",&zheng);
    printf("? %d %d",(qi==1?n:qi-1),zhong);cout<<endl;
    scanf("%d",&fu);
    if (zheng<=fu)
    {
        int l=0,r=tiao(qi,n/2)==zhong?n/2:n/2+1,mid,w=-1;
        while (l<=r)
        {
            mid=(l+r)/2;
            printf("? %d %d",qi,tiao(qi,mid));cout<<endl;
            int xin;scanf("%d",&xin);
            if (dis(qi,tiao(qi,mid))-xin==cha)  w=tiao(qi,mid),r=mid-1;
            else                                l=mid+1;
        }
        int ling=tiao(w,-(cha+1)),bian;
        printf("? %d %d",w,ling);cout<<endl;
        scanf("%d",&bian);
        if (bian==1)    {printf("! %d %d",w,ling);cout<<endl;return ;}
        ling=tiao(qi,-(ling-qi));
        printf("? %d %d",w,ling);cout<<endl;
        scanf("%d",&bian);
        if (bian==1)    {printf("! %d %d",w,ling);cout<<endl;return ;}
    }
    else
    {
        int l=tiao(qi,-n/2)==zhong?-n/2:-(n/2+1),r=0,mid,w=-1;
        while (l<=r)
        {
            mid=(l+r)/2;
            printf("? %d %d",qi,tiao(qi,mid));cout<<endl;
            int xin;scanf("%d",&xin);
            if (dis(qi,tiao(qi,mid))-xin==cha) w=tiao(qi,mid),l=mid+1;
            else                            r=mid-1;
        }
        int ling=tiao(w,-(cha+1)),bian;
        printf("? %d %d",w,ling);cout<<endl;
        scanf("%d",&bian);
        if (bian==1)    {printf("! %d %d",w,ling);cout<<endl;return ;}
        ling=tiao(qi,-(ling-qi));
        printf("? %d %d",w,ling);cout<<endl;
        scanf("%d",&bian);
        if (bian==1)    {printf("! %d %d",w,ling);cout<<endl;return ;}
    }
    cout<<"shit"<<endl;
}
int main()
{
    // freopen("in.in","r",stdin);
    // freopen("out.out","w",stdout);
    int T;scanf("%d",&T);
    while (T--) solve(),scanf("%*d");
    return 0;
}

详细

Test #1:

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

input:

2
6
2
1
2
1
2
2
1
1
4
1
1
1
1
1
1
1

output:

? 1 4
? 2 4
? 6 4
? 1 2
? 1 3
? 1 4
? 4 2
! 4 2
? 1 3
? 2 3
? 4 3
? 1 2
? 1 3
? 3 1
! 3 1

result:

ok ok (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3712kb

input:

1000
15
5
4
6
3
5
6
5
1
1
19
5
4
6
4
7
6
5
5
6

output:

? 1 8
? 2 8
? 15 8
? 1 4
? 1 6
? 1 7
? 1 8
? 8 5
! 8 5
? 1 10
? 2 10
? 19 10
? 1 5
? 1 8
? 1 9
? 1 10
? 10 5
? 10 16
shit

result:

wrong answer You should either "?" or "!". (test case 2)