結果
問題 | No.1767 BLUE to RED |
ユーザー | fukafukatani |
提出日時 | 2021-12-11 20:31:25 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 1,817 bytes |
コンパイル時間 | 17,063 ms |
コンパイル使用メモリ | 377,360 KB |
実行使用メモリ | 16,420 KB |
最終ジャッジ日時 | 2024-07-20 03:12:47 |
合計ジャッジ時間 | 16,668 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:20:10 | 20 | let (n, m) = (v[0], v[1]); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `m` --> src/main.rs:20:13 | 20 | let (n, m) = (v[0], v[1]); | ^ help: if this is intentional, prefix it with an underscore: `_m`
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::<usize>(); let (n, m) = (v[0], v[1]); let a = read_vec::<i64>(); let b = read_vec::<i64>(); let mut events = vec![]; for &anum in &a { events.push((anum, 'A')); } for &bnum in &b { events.push((bnum, 'B')); } events.sort(); let mut ans = 0; let mut q = BinaryHeap::new(); let mut ab_found = false; for i in 0..events.len() - 1 { let prev = events[i]; let cur = events[i + 1]; if prev.1 == 'A' && cur.1 == 'A' { continue; } q.push(Reverse(cur.0 - prev.0)); if prev.1 == 'A' && cur.1 == 'B' { ab_found = true; } if prev.1 == 'B' && cur.1 == 'A' { if ab_found { while q.len() > 1 { ans += q.pop().unwrap().0; } } else { while q.len() > 0 { ans += q.pop().unwrap().0; } } q.clear() } } while q.len() > 0 { ans += q.pop().unwrap().0; } println!("{}", ans); } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }