QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630436#8239. Mysterious Treezyq_313#WA 1ms3632kbC++144.0kb2024-10-11 18:32:442024-10-11 18:32:45

Judging History

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

  • [2024-10-11 18:32:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3632kb
  • [2024-10-11 18:32:44]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
const int N = 3e5 + 10;
using ll = long long;

int n;

int ask(int a, int b){
    cout << "? " << a << ' ' << b << endl;
    int ans;
    cin >> ans;

    return ans;


}

bool have_edge[510];

void solve(){
    cin >> n;
    int o1, o2;
    int flag = 0;

    if (n & 1){
        for (int i = 1; i <= n / 2; i ++){
            // have_edge[i] = ask(2 * i - 1, 2 * i);
            int r = ask(2 * i - 1, 2 * i);
            if (r){
                o1 = 2 * i - 1, o2 = 2 * i;
                flag = 1;
                break;
            }

        }

        if (!flag){
            int r = ask(n, 1);
            if (r){
                o1 = n, o2 = 1;
                flag = 1;
            }
        }

        if (!flag){
            cout << "! 1" << endl;
        }
        if (max(o1, o2) == n){
            int r = ask(2, o1), r1 = ask(2, o2);
            if (r == 0 && r1 == 0){
                cout << "! 1" << endl;
            }else if (r == 1){
                int r2 = ask(3, o1);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }else if (r1 == 1){
                int r2 = ask(3, o2);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }
        }else{
            int r = ask(o1 - 2, o1), r1 = ask(o1 - 2, o2);
            if (r == 0 && r1 == 0){
                cout << "! 1" << endl;
            }else if (r == 1){
                int r2 = ask(o1 - 1, o1);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }else if (r1 == 1){
                int r2 = ask(o1 - 1, o2);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }
        }


    }else{
        for (int i = 1; i <= n / 2; i ++){
            // have_edge[i] = ask(2 * i - 1, 2 * i);
            int r = ask(2 * i - 1, 2 * i);
            if (r){
                o1 = 2 * i - 1, o2 = 2 * i;
                flag = 1;
                break;
            }

        }

        if (!flag){
            cout << "! 1" << endl;
        }
        if (max(o1, o2) == n){
            int r = ask(2, o1), r1 = ask(2, o2);
            if (r == 0 && r1 == 0){
                cout << "! 1" << endl;
            }else if (r == 1){
                int r2 = ask(3, o1);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }else if (r1 == 1){
                int r2 = ask(3, o2);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }
        }else{
            int r = ask((o1 - 2 + n) % n + 1, o1), r1 = ask((o1 - 2 + n) % n, o2);
            if (r == 0 && r1 == 0){
                cout << "! 1" << endl;
            }else if (r == 1){
                int r2 = ask((o1 - 1 + n) % n, o1);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }else if (r1 == 1){
                int r2 = ask((o1 - 1 + n) % n, o2);
                if (r2 != 1){
                    cout << "! 1" << endl;
                }else{
                    cout << "! 2" << endl;
                }
            }
        }

    }


}

int main(){

    // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t --) solve();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3632kb

input:

2
4
1
0
1

output:

? 1 2
? 4 1
? 3 2
? 0 2

result:

wrong answer Integer 0 violates the range [1, 4] (test case 1)