QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416366#8239. Mysterious TreeGodwang#TL 0ms0kbC++143.2kb2024-05-21 19:42:352024-05-21 19:42:38

Judging History

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

  • [2024-05-21 19:42:38]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-21 19:42:35]
  • 提交

answer

#include <iostream>
using namespace std;
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <random>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll ,ll > 
#define endl '\n'
const double pai = acos(-1);
ll extend_gcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
ll fastpow(ll a, ll n, ll mod)
{
    ll ans = 1;
    a %= mod;
    while (n)
    {
        if (n & 1)
            ans = (ans * a)%mod; //% mod
        a = (a * a)%mod;         //% mod
        n >>= 1;
    }
    return ans;
}
int dir[4][2] =
    {
        {0, 1}, {0, -1}, {1, 0}, {-1, 0}}; // d a w s

const ll inf = 1000000000000000000ll;
const ll mod = 1e9 + 7, P1 = 13331;
const double eps = 1e-7;
const int N = 4e5 + 10, M = 1e6 + 10;

int t,n;
ll a[N];
int query(int u,int v)
{
    cout<<"? "<<u<<' '<<v<<endl;
    int ans;
    cin>>ans;
    return ans;
}
void solve()
{
    int n;
    cin>>n;
    bool flag=false;
    int pos1=-1,pos2=-1;
    for(int i=1;i+1<=n;i+=2)
    {
        int ans=query(i,i+1);
        if(ans==1)
        {
            pos1=i;
            pos2=i+1;
            flag=true;
            break;
        }
    }
    if(flag==false&&n%2==1)
    {
        if(query(1,n)==1)
        {
            flag=true;
            pos1=1;
            pos2=n;
        }
    }
    if(!flag)
    {
        cout<<"! 1"<<endl;
        return;
    }
    else
    {
        int cnt=3;
        int cnt1=0,cnt0=0;
        vector<int>candidate;
        for(int i=1;i<=n;i++)
        {
            if(i==pos1||i==pos2)
                continue;
            candidate.push_back(i);
            if(candidate.size()==2)
                break;
        }
        int ans1=query(candidate[0],pos1);
        if(ans1==true)
        {
            int ans2=query(candidate[1],pos1);
            if(ans2==true)
            {
                cout<<"! 2"<<endl;
                return;
            }
            else if(ans2==false)
            {
                cout<<"! 1"<<endl;
                return;
            }
        }
        else if(ans1==false)
        {
            int ans2=query(candidate[0],pos2);
            int ans3=query(candidate[1],pos2);
            if(ans2&&ans3)
            {
                cout<<"! 2"<<endl;
            }
            else
            {
                cout<<"! 1"<<endl;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("ain.txt", "r", stdin);freopen("aout.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
4

output:


result: