QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883366#9734. Identify Chordbyron10000TL 0ms0kbC++142.3kb2025-02-05 16:03:482025-02-05 16:03:54

Judging History

This is the latest submission verdict.

  • [2025-02-05 16:03:54]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2025-02-05 16:03:48]
  • Submitted

answer

#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define fi first
#define se second
#define _UN using namespace
using namespace std;
const int MAXN=510;
int n,_ansa,_ansb,_askc;
int dis(int u,int v){ return min(abs(u-v),n-abs(u-v)); }
int ask(int u,int v){
#ifdef _LOCAL_
    ++_askc;
    return min({dis(u,v),dis(u,_ansa)+1+dis(_ansb,v),dis(u,_ansb)+1+dis(_ansa,v)});
#else
    cout<<"? "<<u+1<<" "<<v+1<<endl;
    int r; cin>>r; return r;
#endif
}
void report(int u,int v){
#ifdef _LOCAL_
    assert(minmax(u,v)==minmax(_ansa,_ansb)); assert(_askc<=40);
#else
    cout<<"1 "<<u+1<<" "<<v+1<<endl;
    int r; cin>>r;
    if(r==-1) exit(0);
#endif
}
mt19937 rng;
void case_main(){
    cin>>n;
#ifdef _LOCAL_
    _askc=0;
    cin>>_ansa>>_ansb;
#endif
    int a=-1,b=-1,d0=-1;
    while(true){
        int u=int(rng()%n),v=(u+n/2)%n;
        auto d=ask(u,v);
        if(d<dis(u,v)){ a=u,b=v,d0=d; break; }
    }
    int p=-1,c;
    if(ask((a+1)%n,b)<d0){
        int l=0,r=(b-a+n)%n-1;
        while(l<=r){
            auto mid=(l+r)/2;
            if(ask((a+mid)%n,b)==d0-mid) p=mid,l=mid+1;
            else r=mid-1;
        }
        assert(p!=-1);
        c=(a+p)%n;
    }else if(ask((a-1+n)%n,b)<d0){
        int l=0,r=(a-b+n)%n-1;
        while(l<=r){
            auto mid=(l+r)/2;
            if(ask((a-mid+n)%n,b)==d0-mid) p=mid,l=mid+1;
            else r=mid-1;
        }
        assert(p!=-1);
        c=(a-p+n)%n;
    }else p=0,c=a;
    assert(d0-p-1>=0);
    int d=(b+(d0-p-1))%n;
    if(ask(c,d)==1) report(c,d);
    else{
        d=(b-(d0-p-1)+n)%n;
//      assert(ask(c,d)==1);
        report(c,d);
    }
}

int main(){
#if defined(_LOCAL_)
    freopen("in","r",stdin);
//  freopen("out","w",stdout);
//  freopen("/dev/null","w",stderr);
#else
//  freopen("game.in","r",stdin);
//  freopen("game.out","w",stdout);
#endif
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int cas; cin>>cas;
    RNG(_,1,cas) case_main();
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

2
6
3
2
1
1
1
1

output:

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

result: