結果
問題 | No.2307 [Cherry 5 th Tune *] Cool 46 |
ユーザー | haihamabossu |
提出日時 | 2023-05-19 22:01:01 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 427 ms / 2,000 ms |
コード長 | 2,993 bytes |
コンパイル時間 | 16,612 ms |
コンパイル使用メモリ | 379,328 KB |
実行使用メモリ | 15,320 KB |
最終ジャッジ日時 | 2024-12-21 02:36:15 |
合計ジャッジ時間 | 51,335 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 46 |
ソースコード
pub mod scanner { pub struct Scanner { buf: Vec<String>, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next<T: std::str::FromStr>(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec<String> { source .split_whitespace() .rev() .map(String::from) .collect::<Vec<_>>() } } } use std::collections::{BTreeMap, BTreeSet, BinaryHeap}; use crate::scanner::Scanner; fn main() { let mut scanner = Scanner::new(); let t: usize = scanner.next(); for _ in 0..t { solve(&mut scanner); } } fn solve(scanner: &mut Scanner) { let n: usize = scanner.next(); let m: usize = scanner.next(); let mut count = BTreeMap::new(); let a: Vec<usize> = (0..n) .map(|_| { let x = scanner.next::<usize>(); *count.entry(x).or_insert(0) += 1; x }) .collect(); let b: Vec<usize> = (0..m) .map(|_| { let x = scanner.next::<usize>(); *count.entry(x).or_insert(0) += 1; x }) .collect(); if n == 0 || m == 0 { println!("Yes"); if n == 0 { for i in 0..m { println!("Blue {}", b[i]); } } else { for i in 0..n { println!("Red {}", a[i]); } } return; } let mut c = BTreeSet::new(); let mut q = BinaryHeap::new(); for (&k, &v) in count.iter() { if v == 2 { c.insert(k); q.push(k); } } let c = c; if c.len() == 0 { println!("No"); return; } println!("Yes"); for i in 0..n { if c.contains(&a[i]) { continue; } else { println!("Red {}", a[i]); } } { let now = q.pop().unwrap(); println!("Red {}", now); println!("Blue {}", now); } for i in 0..m { if c.contains(&b[i]) { continue; } else { println!("Blue {}", b[i]); } } let mut turn = 1; while let Some(now) = q.pop() { if turn == 0 { println!("Red {}", now); println!("Blue {}", now); turn = 1; } else { println!("Blue {}", now); println!("Red {}", now); turn = 0; } } }