QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#323914#8239. Mysterious Treeucup-team1055#RE 1ms3728kbC++201.8kb2024-02-10 14:13:312024-02-10 14:13:31

Judging History

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

  • [2024-02-10 14:13:31]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3728kb
  • [2024-02-10 14:13:31]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template<class T>
bool chmin(T &a, T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

template<class T>
bool chmax(T &a, T b) {
    if(a >= b) return false;
    a = b;
    return true;
}

void solve() {
    int n;
    std::cin >> n;
    auto query = [&](int u, int v) -> int {
        std::cout << "? " << u << " " << v << std::endl;
        int a;
        std::cin >> a;
        return a;
    };
    auto is_star = [&](int u, int v) -> bool {
        int x = 1;
        while(x == u || x == v) x++;
        int a = query(x, u);
        int b = query(x, v);
        int y = -1;
        if(a == 1) y = u;
        else if(b == 1) y = v;
        else assert(0);
        int z = 1;
        while(z == x || z == u || z == v) z++;
        int c = query(y, z);
        return c == 1;
    };
    auto answer = [&](int u, int v) -> void {
        if(is_star(u, v)) {
            std::cout << "! 2" << std::endl;
        }
        else {
            std::cout << "! 1" << std::endl;
        }
    };
    rep(i,0,n/2) {
        int u = 2 * i + 1;
        int v = 2 * i + 2;
        int res = query(u, v);
        if(res == 1) {
            answer(u, v);
            return;
        }
    }
    if(n % 2 == 1) {
        int u = n-1;
        int v = n;
        int res = query(u, v);
        if(res == 1) {
            answer(u, v);
            return;
        }
    }
    std::cout << "! 1" << std::endl;
}

int main() {
    int t;
    std::cin >> t;
    while(t--) {
        solve();
    }
}

详细

Test #1:

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

input:

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

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: -100
Runtime Error

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
1
0
1
1
15
0
0
0
1
0
0

output:

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

result: