結果
問題 | No.2667 Constrained Permutation |
ユーザー | akakimidori |
提出日時 | 2024-03-08 22:58:09 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,630 bytes |
コンパイル時間 | 12,057 ms |
コンパイル使用メモリ | 387,252 KB |
実行使用メモリ | 10,296 KB |
最終ジャッジ日時 | 2024-09-29 20:28:24 |
合計ジャッジ時間 | 14,355 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,824 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 17 ms
6,816 KB |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 46 ms
9,724 KB |
testcase_15 | AC | 44 ms
8,448 KB |
testcase_16 | AC | 31 ms
6,820 KB |
testcase_17 | AC | 10 ms
6,816 KB |
testcase_18 | AC | 48 ms
10,144 KB |
testcase_19 | AC | 47 ms
10,288 KB |
testcase_20 | AC | 49 ms
10,240 KB |
testcase_21 | AC | 55 ms
10,296 KB |
testcase_22 | AC | 58 ms
10,240 KB |
testcase_23 | AC | 57 ms
10,248 KB |
testcase_24 | AC | 20 ms
6,816 KB |
testcase_25 | AC | 38 ms
8,704 KB |
testcase_26 | AC | 48 ms
10,240 KB |
testcase_27 | AC | 48 ms
10,112 KB |
testcase_28 | AC | 32 ms
8,064 KB |
testcase_29 | AC | 30 ms
7,808 KB |
testcase_30 | AC | 34 ms
8,720 KB |
testcase_31 | AC | 21 ms
6,816 KB |
testcase_32 | AC | 5 ms
6,816 KB |
testcase_33 | WA | - |
testcase_34 | AC | 22 ms
6,816 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 45 ms
8,184 KB |
testcase_39 | AC | 2 ms
6,816 KB |
testcase_40 | AC | 23 ms
6,816 KB |
testcase_41 | AC | 38 ms
9,088 KB |
testcase_42 | AC | 26 ms
6,820 KB |
testcase_43 | AC | 37 ms
8,660 KB |
testcase_44 | AC | 16 ms
6,816 KB |
testcase_45 | AC | 1 ms
6,816 KB |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> src/main.rs:2:5 | 2 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: value assigned to `ans` is never read --> src/main.rs:28:9 | 28 | ans = 0; | ^^^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default warning: unused variable: `k` --> src/main.rs:29:23 | 29 | let mut ok = |k: usize| -> bool { | ^ help: if this is intentional, prefix it with an underscore: `_k` | = note: `#[warn(unused_variables)]` on by default warning: type alias `Map` is never used --> src/main.rs:4:6 | 4 | type Map<K, V> = BTreeMap<K, V>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Set` is never used --> src/main.rs:5:6 | 5 | type Set<T> = BTreeSet<T>; | ^^^ warning: type alias `Deque` is never used --> src/main.rs:6:6 | 6 | type Deque<T> = VecDeque<T>; | ^^^^^
ソースコード
use std::collections::*; use std::io::Write; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; type Deque<T> = VecDeque<T>; fn main() { input! { n: usize, p: [(usize, usize); n], } let mut p = p; for p in p.iter_mut() { p.0 += 2 * n; p.1 += 2 * n; } p.sort_by_key(|p| p.0); let s = (0..n).map(|i| p[i].0 - i).max().unwrap(); p.sort_by_key(|p| p.1); let t = (0..n).map(|i| p[i].1 - i).min().unwrap(); if t < s { println!("0"); return; } let mut ans = t - s + 1; if t - s <= 100 { ans = 0; let mut ok = |k: usize| -> bool { p.sort_by_key(|p| p.0); let mut h = BinaryHeap::new(); let mut x = 0; for i in 0..n { while x < n && p[x].0 <= s + i { h.push(!p[x].1); x += 1; } let v = h.pop().unwrap(); if v < s + i { return false; } } true }; ans = (s..=t).filter(|k| ok(*k)).count(); } println!("{}", ans); } // ---------- 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 ----------