結果

問題 No.2667 Constrained Permutation
ユーザー akakimidoriakakimidori
提出日時 2024-03-08 22:57:04
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 2,604 bytes
コンパイル時間 15,303 ms
コンパイル使用メモリ 386,996 KB
実行使用メモリ 10,488 KB
最終ジャッジ日時 2024-09-29 20:26:24
合計ジャッジ時間 18,479 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 0 ms
6,820 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 38 ms
8,064 KB
testcase_29 AC 37 ms
7,808 KB
testcase_30 AC 40 ms
8,780 KB
testcase_31 AC 25 ms
6,816 KB
testcase_32 AC 6 ms
6,816 KB
testcase_33 WA -
testcase_34 AC 26 ms
6,820 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 26 ms
6,816 KB
testcase_41 AC 43 ms
8,960 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
 --> src/main.rs:2:5
  |
2 | use std::io::Write;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: variable `ans` is assigned to, but never used
  --> src/main.rs:26:13
   |
26 |     let mut ans = t - s + 1;
   |             ^^^
   |
   = note: consider using `_ans` instead
   = note: `#[warn(unused_variables)]` 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: value assigned to `ans` is never read
  --> src/main.rs:45:9
   |
45 |         ans = (s..=t).filter(|k| ok(*k)).count();
   |         ^^^
   |
   = help: maybe it is overwritten before being read?

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`

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>;
  |      ^^^^^

ソースコード

diff #

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 <= 10 {
        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();
    }
}

// ---------- 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 ----------
0