結果

問題 No.1676 Coin Trade (Single)
ユーザー ziitaziita
提出日時 2021-09-10 22:53:15
言語 Rust
(1.77.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,739 bytes
コンパイル時間 6,351 ms
コンパイル使用メモリ 142,416 KB
実行使用メモリ 13,128 KB
最終ジャッジ日時 2023-09-02 20:15:52
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 41 ms
9,708 KB
testcase_04 AC 37 ms
8,720 KB
testcase_05 AC 32 ms
7,888 KB
testcase_06 AC 34 ms
7,976 KB
testcase_07 AC 27 ms
6,640 KB
testcase_08 AC 14 ms
4,372 KB
testcase_09 AC 26 ms
6,516 KB
testcase_10 AC 27 ms
6,924 KB
testcase_11 AC 42 ms
10,236 KB
testcase_12 AC 20 ms
5,128 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 1 ms
4,368 KB
testcase_15 AC 1 ms
4,368 KB
testcase_16 AC 1 ms
4,368 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 1 ms
4,368 KB
testcase_19 AC 1 ms
4,368 KB
testcase_20 AC 1 ms
4,372 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 1 ms
4,372 KB
testcase_23 AC 1 ms
4,368 KB
testcase_24 AC 1 ms
4,372 KB
testcase_25 AC 1 ms
4,368 KB
testcase_26 AC 1 ms
4,372 KB
testcase_27 AC 1 ms
4,368 KB
testcase_28 AC 1 ms
4,372 KB
testcase_29 AC 1 ms
4,372 KB
testcase_30 AC 1 ms
4,372 KB
testcase_31 AC 1 ms
4,372 KB
testcase_32 AC 1 ms
4,368 KB
testcase_33 AC 60 ms
13,096 KB
testcase_34 AC 59 ms
13,128 KB
testcase_35 AC 57 ms
13,124 KB
testcase_36 AC 58 ms
13,112 KB
testcase_37 AC 56 ms
13,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

// ---------- begin input macro ----------
// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254 より
pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
    line
}

macro_rules! read {
    ($($t:tt),*; $n:expr) => {{
        let stdin = ::std::io::stdin();
        let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
            let line = line.unwrap();
            let mut it = line.split_whitespace();
            _read!(it; $($t),*)
        }).collect::<Vec<_>>();
        ret
    }};
    ($($t:tt),*) => {{
        let line = readln();
        let mut it = line.split_whitespace();
        _read!(it; $($t),*)
    }};
}

macro_rules! _read {
    ($it:ident; [char]) => {
        _read!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        Vec::from(_read!($it; String).into_bytes())
    };
    ($it:ident; usize1) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_read!($it; $t)),*)
    };
}
// ---------- end input macro ----------


use std::cmp::*;
use std::collections::*;
use std::ops::*;
use std::marker::*;
 
const INF: i64 = std::i64::MAX/100;
const MOD: i64 = 1_000_000_007;
// const MOD: i64 = 998_244_353;

fn main() {
    let (n,m) = read!(usize,usize);
    let mut a = vec![];
    let mut edge = vec![vec![];n];
    for i in 0..n {
        let (v,m) = read!(i64,usize);
        let b = read!([usize]);
        a.push(v);
        for &b in &b {
            edge[b-1].push(i);
        }
    }
    let mut dp = vec![vec![0;2];n];
    for i in 0..n {
        dp[i][1] = -a[i];
    }
    for v in 0..n {
        if v>0 {
            dp[v][0] = dp[v][0].max(dp[v-1][0]);
        }
        dp[v][0] = dp[v][0].max(dp[v][1]+a[v]);
        dp[v][1] = dp[v][1].max(dp[v][0]-a[v]);
        for &e in &edge[v] {
            dp[e][0] = dp[e][0].max(dp[v][0]);
            dp[e][1] = dp[e][1].max(dp[v][1]);
        }
    }
    let mut ans = 0;
    for i in 0..n {
        ans = ans.max(dp[i][0]);
        ans = ans.max(dp[i][1]+a[i]);
    }
    println!("{}",ans);
}
0