結果

問題 No.561 東京と京都
ユーザー taotao54321taotao54321
提出日時 2018-10-11 07:28:41
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,448 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 160,124 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-20 19:40:14
合計ジャッジ時間 4,219 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]

use std::cmp;
use std::io::{ self, prelude::* };

macro_rules! pick {
    ($tokens:expr) => {
        $tokens.next().unwrap().parse().expect("parse error")
    }
}

struct Solver {
    N: usize,
    D: i64,
    A: [Vec<i64>; 2],
}

impl Solver {
    fn f(&self, i: usize, j: usize) -> i64 {
        assert!(i < self.N);
        assert!(j == 0 || j == 1);

        if i == self.N-1 {
            match j {
                0 => cmp::max(self.A[0][i], self.A[1][i]-self.D),
                1 => cmp::max(self.A[1][i], self.A[0][i]-self.D),
                _ => unreachable!(),
            }
        }
        else {
            match j {
                0 => cmp::max(self.A[0][i]+self.f(i+1,0), self.A[1][i]+self.f(i+1,1)-self.D),
                1 => cmp::max(self.A[1][i]+self.f(i+1,1), self.A[0][i]+self.f(i+1,0)-self.D),
                _ => unreachable!(),
            }
        }
    }
}

fn main() {
    let mut s = String::new();
    io::stdin().read_to_string(&mut s).expect("i/o error");
    let mut tokens = s.split_whitespace();

    let N: usize = pick!(tokens);
    let D: i64   = pick!(tokens);

    let mut T = Vec::<i64>::with_capacity(N);
    let mut K = Vec::<i64>::with_capacity(N);
    for _ in 0..N {
        T.push(pick!(tokens));
        K.push(pick!(tokens));
    }

    let solver = Solver {
        N,
        D,
        A: [T, K],
    };
    let ans = solver.f(0,0);

    println!("{}", ans);
}
0