QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#366966#8239. Mysterious TreemeronriTL 1ms3736kbC++142.2kb2024-03-25 15:19:232024-03-25 15:19:23

Judging History

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

  • [2024-03-25 15:19:23]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3736kb
  • [2024-03-25 15:19:23]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void work()
{
    int N;scanf("%d",&N);
    int times=(N+1)/2+3;
    int ans;
    for (int i=1;i*2<=N;i++)
    {
        int x=i*2-1,y=i*2,z,w;
        printf("? %d %d\n",x,y);
        fflush(stdout);
        scanf("%d",&ans);
        if  (ans==1)
            {
                z=x==1?N:x-1;
                w=z==1?N:z-1;
                printf("? %d %d\n",x,z);
                fflush(stdout);
                scanf("%d",&ans);
                if  (ans==1)
                    {
                        printf("? %d %d\n",x,w);
                        fflush(stdout);
                        scanf("%d",&ans);
                        if  (ans==1)
                        {
                            printf("! 2\n");
                            fflush(stdout);
                            return;
                        }
                        else
                        {
                            printf("! 1\n");
                            fflush(stdout);
                            return;
                        }
                    }
                else
                {
                    printf("? %d %d\n",y,z);
                    fflush(stdout);
                    scanf("%d",&ans);
                    if  (ans==1)
                    {
                        printf("? %d %d\n",y,w);
                        fflush(stdout);
                        scanf("%d",&ans);
                        if  (ans==1)
                        {
                            printf("! 2\n");
                            fflush(stdout);
                            return;
                        }
                        else
                        {
                            printf("! 1\n");
                            fflush(stdout);
                            return;
                        }
                    }
                    else
                    {
                        printf("! 1\n");
                        fflush(stdout);
                        return;
                    }
                }
            }
    }
}
int main()
{
    int T;scanf("%d",&T);
    while (T--) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1
0
0
4
0
1
1
1

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

87
13
0
0
0
0
0
1
0
1
1
15
0
0
0
0
0
0
1
1
1
7
0
0
0

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 11 10
? 12 10
? 12 9
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 13 12
? 13 11
! 2
? 1 2
? 3 4
? 5 6

result: