結果
問題 |
No.945 YKC饅頭
|
ユーザー |
|
提出日時 | 2020-01-22 22:44:01 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 302 ms / 2,000 ms |
コード長 | 2,949 bytes |
コンパイル時間 | 22,232 ms |
コンパイル使用メモリ | 402,540 KB |
実行使用メモリ | 49,836 KB |
最終ジャッジ日時 | 2024-07-16 03:57:04 |
合計ジャッジ時間 | 30,475 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
ソースコード
use std::io::Read; use std::collections::{HashMap, BinaryHeap}; fn main() { const MIN_VAL: isize = -10_000_000; let mut all_data = String::new(); std::io::stdin().read_to_string(&mut all_data).ok(); let all_data: Vec<&str> = all_data.trim().split('\n').map(|s| s.trim()).collect(); let nm: Vec<isize> = all_data.iter().next().unwrap().split_whitespace().map(|i| i.parse::<isize>().unwrap()).collect(); let n: isize = nm[0]; let m: isize = nm[1]; let mut idx2kmc: HashMap<usize, String> = HashMap::new(); let mut starts: BinaryHeap<isize> = BinaryHeap::new(); let mut ends: BinaryHeap<isize> = BinaryHeap::new(); let mut mapping: Vec<Vec<isize>> = vec![vec![]; (n as usize)+2]; all_data.iter().enumerate().skip(1).take(m as usize).for_each(|pair| { let mark_val = pair.0 as isize; let values: Vec<&str> = (pair.1).split_whitespace().collect(); let start: usize = values[0].parse::<usize>().unwrap(); let end: usize = values[1].parse::<usize>().unwrap(); let keyword: String = values[2].to_string(); idx2kmc.insert(mark_val as usize, keyword); mapping[start].push(mark_val); mapping[end+1].push(-mark_val); }); let mut result_map: Vec<Option<String>> = vec![None; n as usize]; let mut current_val: isize = MIN_VAL; mapping.iter().skip(1).take(n as usize).enumerate().for_each(|pair| { let start_ends = pair.1; if !start_ends.is_empty() { start_ends.iter().for_each(|se| { if se > &0isize { starts.push(-se); } else { ends.push(*se); } }); } if !ends.is_empty() { if ends.peek().unwrap() == ¤t_val { current_val = MIN_VAL; ends.pop(); } } while !starts.is_empty() && !ends.is_empty() { if starts.peek().unwrap() != ends.peek().unwrap() { break; } else { starts.pop(); ends.pop(); } } if !starts.is_empty() { if starts.peek().unwrap() > ¤t_val { if current_val > MIN_VAL { starts.push(current_val); } current_val = starts.pop().unwrap(); } } let v = (-current_val) as usize; result_map[pair.0] = idx2kmc.get(&v).map(|i| i.to_string()); }); let mut y = 0; let mut k = 0; let mut c = 0; result_map.iter().for_each(|r| { match r { Some(x) => { match x.as_str() { "Y" => { y += 1; }, "K" => { k += 1; }, "C" => { c += 1; }, _ => { }, } }, None => { }, } }); println!("{} {} {}", y, k, c); }