QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#323914 | #8239. Mysterious Tree | ucup-team1055# | RE | 1ms | 3728kb | C++20 | 1.8kb | 2024-02-10 14:13:31 | 2024-02-10 14:13:31 |
Judging History
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