QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527222#8239. Mysterious Treemhw#WA 1ms3616kbC++231.3kb2024-08-22 12:29:382024-08-22 12:29:38

Judging History

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

  • [2024-08-22 12:29:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-08-22 12:29:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define inf 0x3f3f3f3f
#define db double
#define il inline
#define x first
#define y second
const int N = 2e5 + 5;
const int mod = 998244353;
int ask(int u,int v)
{
    cout<<"? "<<u<<" "<<v<<endl;
    int s;cin>>s;
    return s;
}
void solve()
{
    int n;cin>>n;
    int s=0;
    for(int i=1;i<=n;i+=2)
    {
        if(ask(i,i+1)) 
        {
            s=i;
            break;
        }
    }
    if(s==0 && (n&1)) 
    {
        if(ask(1,n)) s=n;
    }
    if(s==0) 
    {
        cout<<"! 1\n";
    }
    else 
    {
        int s2;
        if(s!=n) s2=s+1;
        else s2=1;

        int a1=0,a2=0;
        for(int i=1;i<=n;i++)
        {
            if(i==s||i==s2) continue;
            if(a1==0) a1=i;
            else 
            {
                a2=i;
                break;
            }
        }
        int b1=ask(s,a1),b2=ask(s2,a1);
        if(b1==0&&b2==0)
        {
            cout<<"! 1\n";
        }
        else 
        {
            int f;
            if(b1) f=ask(s,a2);
            else f=ask(s2,a2);
            if(f) cout<<"! 2\n";
            else cout<<"! 1\n";
        }
    }
}
signed main()
{
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

详细

Test #1:

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

input:

2
4
1
0
1
0
4
0
1
1
0
1

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3608kb

input:

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

output:

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

result:

wrong answer Integer 8 violates the range [1, 7] (test case 3)