use std::io::Write;
fn main() {
let mut lines = std::io::stdin().lines().map(|x| x.unwrap());
let f = if lines.next().unwrap() == "Algosia" {
a
} else {
b
};
let n = {
let nt = lines
.next()
.unwrap()
.split_whitespace()
.map(|x| str::parse(x).unwrap())
.collect::<Vec<usize>>();
nt[1]
};
for _ in 0..n {
f(&mut lines);
}
}
fn a(lines: &mut impl Iterator<Item = String>) {
let mut n = lines.next()
.unwrap().parse::<u64>()
.unwrap();
println!("1000000000");
for i in 0..9 {
for _ in 0..i {
print!("{}", n % 2);
n /= 2;
}
print!("11");
for _ in 0..(8 - i) {
print!("0");
}
println!();
std::io::stdout().flush().unwrap();
}
}
fn b(lines: &mut impl Iterator<Item = String>) {
let inp = lines
.take(10)
.map(|s| s.chars().map(|x| x == '1').collect::<Vec<_>>())
.collect::<Vec<_>>();
eprintln!("{:?}", inp);
let mut n = 0u64;
let mut add = 1u64;
let mut unknown_col = [true; 10];
let mut known_col = Vec::<usize>::new();
while known_col.len() < 10 {
let this_row = (0..10)
.find(|i| {
inp[*i]
.iter()
.enumerate()
.filter(|(a, b)| unknown_col[*a] && **b)
.count()
== 1
})
.unwrap();
let this_col = inp[this_row]
.iter()
.enumerate()
.find(|(a, b)| unknown_col[*a] && **b)
.unwrap()
.0;
eprintln!("{:?}", (this_row, this_col));
known_col.push(this_col);
unknown_col[this_col] = false;
if let Some((bytes_col, _)) = known_col.split_last_chunk::<2>() {
eprintln!("{:?}", bytes_col);
for i in bytes_col {
if inp[this_row][*i] { n += add; }
add *= 2;
}
eprintln!("{:?}", n);
}
}
println!("{}", n);
std::io::stdout().flush().unwrap();
}
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | use std::io::Write; fn main() { let mut lines = std::io::stdin().lines().map(|x| x.unwrap()); let f = if lines.next().unwrap() == "Algosia" { a } else { b }; let n = { let nt = lines .next() .unwrap() .split_whitespace() .map(|x| str::parse(x).unwrap()) .collect::<Vec<usize>>(); nt[1] }; for _ in 0..n { f(&mut lines); } } fn a(lines: &mut impl Iterator<Item = String>) { let mut n = lines.next() .unwrap().parse::<u64>() .unwrap(); println!("1000000000"); for i in 0..9 { for _ in 0..i { print!("{}", n % 2); n /= 2; } print!("11"); for _ in 0..(8 - i) { print!("0"); } println!(); std::io::stdout().flush().unwrap(); } } fn b(lines: &mut impl Iterator<Item = String>) { let inp = lines .take(10) .map(|s| s.chars().map(|x| x == '1').collect::<Vec<_>>()) .collect::<Vec<_>>(); eprintln!("{:?}", inp); let mut n = 0u64; let mut add = 1u64; let mut unknown_col = [true; 10]; let mut known_col = Vec::<usize>::new(); while known_col.len() < 10 { let this_row = (0..10) .find(|i| { inp[*i] .iter() .enumerate() .filter(|(a, b)| unknown_col[*a] && **b) .count() == 1 }) .unwrap(); let this_col = inp[this_row] .iter() .enumerate() .find(|(a, b)| unknown_col[*a] && **b) .unwrap() .0; eprintln!("{:?}", (this_row, this_col)); known_col.push(this_col); unknown_col[this_col] = false; if let Some((bytes_col, _)) = known_col.split_last_chunk::<2>() { eprintln!("{:?}", bytes_col); for i in bytes_col { if inp[this_row][*i] { n += add; } add *= 2; } eprintln!("{:?}", n); } } println!("{}", n); std::io::stdout().flush().unwrap(); } |
English