QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623829#8239. Mysterious Treebessie_goes_moo#RE 0ms0kbC++171.5kb2024-10-09 14:08:122024-10-09 14:08:14

Judging History

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

  • [2024-10-09 14:08:14]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-09 14:08:12]
  • 提交

answer

#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
int read(){
    int red=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){ if(ch=='-') f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9') red=red*10+ch-48,ch=getchar();
    return red*f;
}
const int N=1e5+5;
typedef long long LL;
typedef pair<int,int> PII;
int T,n;
map<PII,bool>H;
bool star;
bool Query(int x,int y){
    if(x>y) swap(x,y);
    if(H.count(mp(x,y))) return H[mp(x,y)];
    printf("? %d %d\n",x,y);fflush(stdout);
    int z;scanf("%d",&z);
    H[mp(x,y)]=z;
}
bool Work(int x){
    int y;
    if(n-x+1==x) y=1;
    else y=n-x+1;
    if(Query(x,y)){
        for(int k=1;k<=n;k++) if(k!=x&&k!=y){
            if(Query(x,k)){
                for(int kk=k+1;kk<=n;kk++) if(kk!=x&&kk!=y){
                    if(Query(x,kk)){star=1;return 1;}
                    break;
                }
                star=0;return 1;
            }else if(Query(y,k)){
                for(int kk=k+1;kk<=n;kk++) if(kk!=x&&kk!=y){
                    if(Query(y,kk)){star=1;return 1;}
                    break;
                }
                star=0;return 1;
            }
            star=0;return 1;
        }
    }else return 0;
}
int main(){
    // freopen("J.in","r",stdin);
    // freopen("J.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        star=0;H.clear();
        for(int i=n;i>=n/2;i--) if(Work(i)) break;
        if(!star) printf("! 1\n");
        else printf("! 2\n");
        fflush(stdout);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
4
0

output:

? 1 4

result: