結果
問題 | No.1767 BLUE to RED |
ユーザー | fukafukatani |
提出日時 | 2021-12-11 20:31:25 |
言語 | Rust (1.72.1) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 1,817 bytes |
コンパイル時間 | 1,279 ms |
コンパイル使用メモリ | 152,836 KB |
実行使用メモリ | 17,872 KB |
最終ジャッジ日時 | 2023-09-27 09:05:39 |
合計ジャッジ時間 | 5,846 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 0 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 0 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 22 ms
8,880 KB |
testcase_10 | AC | 28 ms
14,028 KB |
testcase_11 | AC | 24 ms
10,984 KB |
testcase_12 | AC | 22 ms
9,444 KB |
testcase_13 | AC | 32 ms
14,832 KB |
testcase_14 | AC | 39 ms
16,864 KB |
testcase_15 | AC | 40 ms
17,648 KB |
testcase_16 | AC | 41 ms
16,336 KB |
testcase_17 | AC | 41 ms
17,400 KB |
testcase_18 | AC | 40 ms
16,324 KB |
testcase_19 | AC | 40 ms
17,872 KB |
testcase_20 | AC | 41 ms
16,336 KB |
testcase_21 | AC | 39 ms
16,548 KB |
testcase_22 | AC | 39 ms
16,596 KB |
testcase_23 | AC | 41 ms
17,340 KB |
コンパイルメッセージ
warning: unused variable: `n` --> 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` --> Main.rs:20:13 | 20 | let (n, m) = (v[0], v[1]); | ^ help: if this is intentional, prefix it with an underscore: `_m` warning: 2 warnings emitted
ソースコード
#![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() }