結果
| 問題 |
No.1368 サイクルの中に眠る門松列
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2021-01-29 22:27:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,616 bytes |
| コンパイル時間 | 11,252 ms |
| コンパイル使用メモリ | 402,852 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-27 08:44:25 |
| 合計ジャッジ時間 | 12,492 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 14 |
コンパイルメッセージ
warning: unused variable: `i`
--> src/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
ソースコード
#![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()
}
fukafukatani