結果
問題 | No.355 数当てゲーム(2) |
ユーザー |
|
提出日時 | 2020-07-12 21:47:44 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 3,453 bytes |
コンパイル時間 | 14,429 ms |
コンパイル使用メモリ | 384,904 KB |
実行使用メモリ | 25,488 KB |
平均クエリ数 | 25.46 |
最終ジャッジ日時 | 2024-07-17 02:48:58 |
合計ジャッジ時間 | 17,396 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
use std::collections::HashSet;fn next_permutation(lists: &mut Vec<usize>) -> bool {let mut n = lists.len();let mut i: usize = n - 1;while i >= 1 && lists[i - 1] > lists[i] {i -= 1;}if i == 0 { return false; }let mut j: usize = i;while j + 1 < n && lists[i - 1] < lists[j + 1] {j += 1;}lists.swap(i-1, j);n -= 1;while n > i {lists.swap(i, n);i += 1;n -= 1;}true}fn main() {let mut asks: Vec<usize> = vec![0,1,2,3];let mut fixed: HashSet<usize> = HashSet::new();println!("{} {} {} {}", asks[0], asks[1], asks[2], asks[3]);let mut xy = String::new();std::io::stdin().read_line(&mut xy).ok();let xy: Vec<usize> = xy.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let x = xy[0];let y = xy[1];let mut prev: usize = x + y;let mut rank: usize = 3;let mut unused: HashSet<usize> = HashSet::new();(4..=9).for_each(|i| { unused.insert(i); });let mut rev_flg = false;if x == 4 && y == 0 {return;}loop {println!("{} {} {} {}", asks[0], asks[1], asks[2], asks[3]);let mut xy = String::new();std::io::stdin().read_line(&mut xy).ok();let xy: Vec<usize> = xy.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let x = xy[0];let y = xy[1];if x == 4 && y == 0 {return;}if x + y == 4 {break;}if x + y != prev {if x + y > prev {fixed.insert(asks[rank]);} else {match rank {3 => {if rev_flg {fixed.insert(asks[3] + 1);} else {fixed.insert(asks[3] - 1);}},_ => {fixed.insert(rank);asks[rank] = rank;},}}if rank == 3 {prev = x + y;}} else {if rank == 3 {let temp = if rev_flg { asks[3] + 1 } else { asks[3] - 1 };if fixed.contains(&temp) {fixed.insert(asks[3]);}}}if fixed.len() == 4 {asks = fixed.iter().map(|i| *i).collect();break;}if rank == 3 {if !rev_flg && asks[3] < 9 {asks[3] += 1;} else {rev_flg = true;if asks[3] > 3 {asks[3] -= 1;} else {rank -= 1;asks[rank] = *unused.difference(&fixed).max().unwrap();}}} else {asks[rank] = rank;rank -= 1;asks[rank] = *unused.difference(&fixed).max().unwrap();}}asks.sort();loop {println!("{} {} {} {}", asks[0], asks[1], asks[2], asks[3]);let mut xy = String::new();std::io::stdin().read_line(&mut xy).ok();let xy: Vec<usize> = xy.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let x = xy[0];let y = xy[1];if x == 4 && y == 0 {return;}next_permutation(&mut asks);}}