結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー fukafukatanifukafukatani
提出日時 2021-01-29 22:27:30
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 160,144 KB
実行使用メモリ 5,912 KB
最終ジャッジ日時 2023-09-09 15:57:02
合計ジャッジ時間 2,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 16 ms
5,868 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:20:9
   |
20 |     for i in 0..t {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let t = read::<usize>();
    for i in 0..t {
        solve();
    }
}

fn solve() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let mut a = a.into_iter().collect::<VecDeque<_>>();
    let mut ret = 0;
    for _ in 0..2 {
        let mut dp = vec![0; n + 1];
        for i in 0..n - 2 {
            for j in 1..=3 {
                if j > i {
                    continue;
                }
                dp[i] = max(dp[i], dp[i - j]);
            }
            if is_kadomatsu((a[i], a[i + 1], a[i + 2])) {
                dp[i + 3] = max(dp[i], dp[i + 3] + a[i]);
            }
        }
        ret = max(ret, *dp.iter().max().unwrap());

        let t = a.pop_back().unwrap();
        a.push_front(t);
    }
    println!("{}", ret);
}

fn is_kadomatsu(a: (i64, i64, i64)) -> bool {
    if a.0 == a.2 {
        return false;
    }
    (a.0 < a.1 && a.1 > a.2) || (a.0 > a.1 && a.1 < a.2)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0