結果

問題 No.1160 Strange Bowling
ユーザー Konton7
提出日時 2020-08-18 21:06:53
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 11,295 ms
コンパイル使用メモリ 395,228 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 03:13:48
合計ジャッジ時間 12,589 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp;
use std::fs::File;
use std::io::Read;

// fn pow_speedt_with_mod(mut p: i64, mut q: i64, m: i64) -> i64 {
//     p %= m;
//     let mut r = p;
//     let mut ret: i64 = 1;
//     while q > 0 {
//         ret *= if q % 2 == 1 {r} else {1};
//         r *= r;
//         r %= m;
//         q /= 2;
//         ret %= m;
//     }
//     return ret;
// }

fn main() {
    let inputstatus = 1;
    let mut buf = String::new();

    let filename = "inputrust.txt";

    if inputstatus == 0 {
        let mut f = File::open(filename).expect("file not found");
        f.read_to_string(&mut buf)
            .expect("something went wrong reading the file");
    } else {
        std::io::stdin().read_to_string(&mut buf).unwrap();
    }

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut dp = vec![vec![0; n]; 2];

    for i in 0..n {
        let p: i32 = iter.next().unwrap().parse().unwrap();
        let a: i32 = iter.next().unwrap().parse().unwrap();
        if i == 0 {
            dp[0][i] = p;
            dp[1][i] = a;
        } else {
            dp[0][i] = cmp::max(dp[0][i - 1] + p, dp[1][i - 1] + 2 * p);
            dp[1][i] = cmp::max(dp[0][i - 1] + a, dp[1][i - 1] + 2 * a);
        }
    }

    println!("{}", cmp::max(dp[0][n - 1], dp[1][n - 1]));
}
0