-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathapc001-c-text-io.rs
48 lines (42 loc) · 1.33 KB
/
apc001-c-text-io.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// https://atcoder.jp/contests/apc001/tasks/apc001_c
//
// 以下のクレートを使用。
// - `text_io`
use std::{cmp, panic, process};
use text_io::read;
fn main() {
panic::set_hook(Box::new(|_| {
// 変なクエリを吐いて`RE`させ、`TLE`を回避
println!("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}));
// `text_io::read!`。
// `read!()`は`read!("{}", std::io::stdin().bytes().map(Result::unwrap))`の短縮となる。
//
// https://docs.rs/text_io/0.1.8/text_io/macro.read.html
let n: usize = read!();
let query = |i: usize| -> _ {
println!("{}", i);
let seat: String = read!();
match &*seat {
"Vacant" => process::exit(0),
"Male" => false,
"Female" => true,
_ => unreachable!(),
}
};
let first = query(0);
let last = query(n - 1);
// Nは小さいので`Vec`を作って`<[_]>::binary_search`を悪用
(1..n)
.collect::<Vec<_>>()
.binary_search_by(|&i| {
let query = query(i);
if (i % 2 == 0) == (query == first) || ((n - i - 1) % 2 == 0) != (query == last) {
cmp::Ordering::Less
} else {
cmp::Ordering::Greater
}
})
.unwrap();
unreachable!();
}