結果

問題 No.1898 Battle and Exchange
ユーザー akakimidoriakakimidori
提出日時 2022-04-08 21:51:12
言語 Rust
(1.77.0)
結果
AC  
実行時間 788 ms / 5,000 ms
コード長 3,204 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 158,548 KB
実行使用メモリ 20,624 KB
最終ジャッジ日時 2023-08-19 00:28:54
合計ジャッジ時間 22,633 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 34 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 18 ms
4,380 KB
testcase_18 AC 102 ms
6,008 KB
testcase_19 AC 162 ms
8,676 KB
testcase_20 AC 181 ms
9,196 KB
testcase_21 AC 544 ms
18,596 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 1 ms
4,388 KB
testcase_27 AC 24 ms
4,380 KB
testcase_28 AC 35 ms
4,380 KB
testcase_29 AC 115 ms
4,376 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 59 ms
8,600 KB
testcase_33 AC 61 ms
14,140 KB
testcase_34 AC 49 ms
6,808 KB
testcase_35 AC 80 ms
9,984 KB
testcase_36 AC 42 ms
9,380 KB
testcase_37 AC 47 ms
4,380 KB
testcase_38 AC 788 ms
20,624 KB
testcase_39 AC 584 ms
17,888 KB
testcase_40 AC 709 ms
19,240 KB
testcase_41 AC 479 ms
17,152 KB
testcase_42 AC 14 ms
4,380 KB
testcase_43 AC 309 ms
15,676 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 29 ms
4,380 KB
testcase_46 AC 140 ms
8,640 KB
testcase_47 AC 29 ms
4,380 KB
testcase_48 AC 75 ms
4,376 KB
testcase_49 AC 19 ms
4,380 KB
testcase_50 AC 18 ms
4,380 KB
testcase_51 AC 19 ms
4,380 KB
testcase_52 AC 48 ms
4,380 KB
testcase_53 AC 242 ms
5,780 KB
testcase_54 AC 342 ms
7,080 KB
testcase_55 AC 295 ms
6,564 KB
testcase_56 AC 382 ms
8,128 KB
testcase_57 AC 437 ms
20,244 KB
testcase_58 AC 775 ms
20,244 KB
testcase_59 AC 653 ms
20,188 KB
testcase_60 AC 575 ms
20,184 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
  --> Main.rs:52:5
   |
52 | use std::io::Write;
   |     ^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: type alias `Map` is never used
  --> Main.rs:54:6
   |
54 | type Map<K, V> = BTreeMap<K, V>;
   |      ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
  --> Main.rs:55:6
   |
55 | type Set<T> = BTreeSet<T>;
   |      ^^^

warning: type alias `Deque` is never used
  --> Main.rs:56:6
   |
56 | type Deque<T> = VecDeque<T>;
   |      ^^^^^

warning: 4 warnings emitted

ソースコード

diff #

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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_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_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 ----------

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 run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1); m],
        p: [[u32; 3]; n],
    }
    let mut g = vec![vec![]; n];
    for (a, b) in e {
        g[a].push(b);
        g[b].push(a);
    }
    let mut p = p;
    for p in p.iter_mut() {
        p.sort();
    }
    let p = p;
    let mut ng = p[0].iter().sum::<u32>();
    let mut ok = p.iter().map(|p| p.iter().sum::<u32>()).max().unwrap() + 1;
    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        let mut hand = vec![1, p[0][2], mid - 2];
        let mut free = vec![];
        free.extend(p[0].iter().take(2).cloned());
        let mut ban = true;
        let mut used = vec![false; n];
        used[0] = true;
        let mut next = BinaryHeap::new();
        for &u in g[0].iter() {
            next.push((!p[u].iter().sum::<u32>(), u));
        }
        while let Some((d, v)) = next.pop() {
            if used[v] {
                continue;
            }
            if !ban {
                hand.append(&mut free);
            }
            hand.sort_by_key(|p| !*p);
            hand.truncate(3);
            let d = !d;
            if hand.iter().sum::<u32>() > d {
                used[v] = true;
                free.extend(p[v].iter());
                ban = false;
                for &u in g[v].iter() {
                    if !used[u] {
                        next.push((!p[u].iter().sum::<u32>(), u));
                    }
                }
            }
        }
        if used[n - 1] {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("1 1 {}", ok - 2);
}

fn main() {
    run();
}
0