結果
問題 | No.2667 Constrained Permutation |
ユーザー | akakimidori |
提出日時 | 2024-03-08 23:01:06 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 2,631 bytes |
コンパイル時間 | 12,352 ms |
コンパイル使用メモリ | 389,512 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2024-09-29 20:30:40 |
合計ジャッジ時間 | 14,549 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 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 | 2 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 1 ms
6,820 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 18 ms
6,820 KB |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 50 ms
9,856 KB |
testcase_15 | AC | 47 ms
8,448 KB |
testcase_16 | AC | 32 ms
6,816 KB |
testcase_17 | AC | 10 ms
6,820 KB |
testcase_18 | AC | 51 ms
10,240 KB |
testcase_19 | AC | 50 ms
10,368 KB |
testcase_20 | AC | 50 ms
10,292 KB |
testcase_21 | AC | 58 ms
10,296 KB |
testcase_22 | AC | 62 ms
10,368 KB |
testcase_23 | AC | 58 ms
10,232 KB |
testcase_24 | AC | 21 ms
6,820 KB |
testcase_25 | AC | 40 ms
8,704 KB |
testcase_26 | AC | 52 ms
10,240 KB |
testcase_27 | AC | 51 ms
10,068 KB |
testcase_28 | AC | 35 ms
8,192 KB |
testcase_29 | AC | 33 ms
7,808 KB |
testcase_30 | AC | 35 ms
8,704 KB |
testcase_31 | AC | 22 ms
6,816 KB |
testcase_32 | AC | 5 ms
6,820 KB |
testcase_33 | AC | 56 ms
9,932 KB |
testcase_34 | AC | 23 ms
6,816 KB |
testcase_35 | AC | 33 ms
6,820 KB |
testcase_36 | AC | 32 ms
6,816 KB |
testcase_37 | AC | 36 ms
7,296 KB |
testcase_38 | AC | 50 ms
8,192 KB |
testcase_39 | AC | 1 ms
6,816 KB |
testcase_40 | AC | 23 ms
6,820 KB |
testcase_41 | AC | 39 ms
9,116 KB |
testcase_42 | AC | 28 ms
6,816 KB |
testcase_43 | AC | 39 ms
8,528 KB |
testcase_44 | AC | 16 ms
6,820 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 ----------