結果
問題 | No.2114 01 Matching |
ユーザー | akakimidori |
提出日時 | 2022-10-29 00:17:16 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,515 bytes |
コンパイル時間 | 15,629 ms |
コンパイル使用メモリ | 398,020 KB |
実行使用メモリ | 73,344 KB |
最終ジャッジ日時 | 2024-07-06 03:29:01 |
合計ジャッジ時間 | 21,878 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 0 ms
6,816 KB |
testcase_02 | AC | 183 ms
24,004 KB |
testcase_03 | AC | 47 ms
17,024 KB |
testcase_04 | AC | 70 ms
23,040 KB |
testcase_05 | WA | - |
testcase_06 | AC | 179 ms
19,608 KB |
testcase_07 | AC | 177 ms
18,388 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 169 ms
18,876 KB |
testcase_11 | AC | 322 ms
73,088 KB |
testcase_12 | AC | 324 ms
73,344 KB |
testcase_13 | WA | - |
testcase_14 | AC | 68 ms
34,512 KB |
testcase_15 | AC | 67 ms
33,900 KB |
testcase_16 | WA | - |
testcase_17 | AC | 174 ms
20,148 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 309 ms
73,088 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 331 ms
73,216 KB |
testcase_27 | AC | 320 ms
73,344 KB |
testcase_28 | AC | 164 ms
41,216 KB |
testcase_29 | AC | 325 ms
73,216 KB |
testcase_30 | AC | 174 ms
22,324 KB |
testcase_31 | AC | 315 ms
73,216 KB |
testcase_32 | WA | - |
testcase_33 | AC | 178 ms
22,804 KB |
testcase_34 | AC | 92 ms
19,896 KB |
testcase_35 | AC | 114 ms
30,976 KB |
testcase_36 | AC | 319 ms
73,216 KB |
testcase_37 | WA | - |
testcase_38 | AC | 164 ms
16,440 KB |
testcase_39 | WA | - |
testcase_40 | AC | 109 ms
30,336 KB |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 165 ms
22,048 KB |
testcase_44 | WA | - |
testcase_45 | AC | 196 ms
73,088 KB |
testcase_46 | WA | - |
testcase_47 | AC | 327 ms
72,960 KB |
testcase_48 | AC | 326 ms
73,088 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 165 ms
24,224 KB |
testcase_52 | AC | 69 ms
35,232 KB |
ソースコード
// https://yukicoder.me/problems/no/1467 // これっぽい感が fn run() { input! { n: usize, m: usize, k: i64, b: [i64; n], r: [i64; m], } let mut map = std::collections::BTreeMap::new(); for &b in b.iter() { map.entry(b % k).or_insert(vec![vec![]; 2])[0].push(b / k); } for &r in r.iter() { map.entry(r % k).or_insert(vec![vec![]; 2])[1].push(r / k); } let mut sum = 0; let mut cnt = 0; let inf = std::i64::MAX / 10; for (_, mut p) in map { if p[0].len() > p[1].len() { p.swap(0, 1); } let mut a = vec![]; a.extend(p[0].iter().map(|p| (*p, 0))); a.extend(p[1].iter().map(|p| (*p, 1))); a.sort(); let mut left = std::collections::BinaryHeap::new(); let mut left_add = 0; let mut right = std::collections::BinaryHeap::new(); let mut right_add = 0; left.push((0, inf)); right.push((0, inf)); if a[0].1 == 0 { left_add += 1; right_add += 1; } else { left_add -= 1; } for a in a.windows(2) { let diff = a[1].0 - a[0].0; let op = a[1].1; let mut d = diff; while d > 0 && left.peek().map_or(false, |p| p.0 + left_add > 0) { let (a, b) = *left.peek().unwrap(); let a = a + left_add; let v = b.min(d); sum += a * v; d -= v; if b == v { left.pop(); } else { left.peek_mut().unwrap().1 -= v; } right.push((right_add - a, v)); } if d > 0 { right.push((right_add, d)); } let mut d = diff; while d > 0 && right.peek().map_or(false, |p| -p.0 + right_add < 0) { let (a, b) = *right.peek().unwrap(); let a = -a + right_add; let v = b.min(d); sum += -a * v; d -= v; if b == v { right.pop(); } else { right.peek_mut().unwrap().1 -= v; } left.push((a - left_add, v)); } if d > 0 { left.push((-left_add, d)); } if op == 0 { left_add += 1; right_add += 1; } else { left_add -= 1; } } for v in left.drain() { let pos = v.0 + left_add; let cnt = v.1; sum += cnt * std::cmp::max(pos, 0); } for v in right.drain() { let pos = -v.0 + right_add; let cnt = v.1; sum += cnt * std::cmp::max(-pos, 0); } cnt += p[0].len(); } if cnt == n.min(m) { println!("{}", sum); } else { println!("-1"); } } fn main() { run(); } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ----------