QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323824 | #8239. Mysterious Tree | ucup-team635# | RE | 0ms | 2152kb | Rust | 1.3kb | 2024-02-10 13:35:51 | 2024-02-10 13:35:53 |
Judging History
answer
use std::io::Write;
use std::collections::*;
type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;
fn main() {
let t = read();
for _ in 0..t {
println!("! {}", solve());
}
}
fn solve() -> usize {
let n = read();
let mut cnt = 0;
let mut query = |a: usize, b: usize| -> usize {
cnt += 1;
assert!(1 <= a.min(b) && a != b && a.max(b) <= n);
assert!(cnt <= (n + 1) / 2 + 3);
println!("? {} {}", a, b);
read()
};
let mut edge = (0, 0);
for i in (1..=n).step_by(2) {
let l = i;
let r = i % n + 1;
if query(l, r) == 1 {
edge = (l, r);
break;
}
}
let (x, y) = edge;
let mut v = (1..=n).collect::<Vec<_>>();
v.retain(|v| *v != x && *v != y);
let a = v[0];
let b = v[1];
if query(x, a) == 1 {
return if query(x, v[1]) == 1 {
2
} else {
1
};
}
if query(y, a) == 0 {
return 1;
}
if query(y, b) == 1 {
2
} else {
1
}
}
fn read() -> usize {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
s.trim().parse().unwrap()
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 2152kb
input:
2 4 1 0 1 0 4 0 1 1 1
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 1 ? 1 2 ? 3 4 ? 3 1 ? 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 1 7 0 0 0 1 1 1 15 0 0 0 1 0 0 19 0 0 0 0 0 1 1 1 20 0 0 0 0 0 0 0 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 ? 13 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 1 ? 7 2 ? 7 3 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 7 1 ? 8 1 ! 1 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 1 ? 11 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 1...