結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー koba-e964koba-e964
提出日時 2021-11-06 19:56:56
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,095 bytes
コンパイル時間 3,160 ms
コンパイル使用メモリ 150,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 08:30:43
合計ジャッジ時間 9,370 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 12 ms
5,376 KB
testcase_06 AC 119 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 276 ms
5,376 KB
testcase_09 AC 61 ms
5,376 KB
testcase_10 AC 294 ms
5,376 KB
testcase_11 AC 299 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 31 ms
5,376 KB
testcase_14 AC 177 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 102 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 299 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 116 ms
5,376 KB
testcase_23 AC 346 ms
5,376 KB
testcase_24 AC 340 ms
5,376 KB
testcase_25 AC 336 ms
5,376 KB
testcase_26 AC 335 ms
5,376 KB
testcase_27 AC 342 ms
5,376 KB
testcase_28 AC 342 ms
5,376 KB
testcase_29 AC 337 ms
5,376 KB
testcase_30 AC 333 ms
5,376 KB
testcase_31 AC 331 ms
5,376 KB
testcase_32 AC 330 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); }
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) { if *self < x { *self = x; } }
    fn chmin(&mut self, x: T) { if *self > x { *self = x; } }
}

fn main() {
    input! {
        n: usize,
        s: chars,
    }
    let pon = ['p', 'o', 'n'];
    const INF: i32 = 1 << 28;
    let mut dp = vec![vec![[-INF; 3]; n + 1]; n];
    for i in 0..n {
        for j in i..n + 1 {
            dp[i][j][0] = 0;
        }
    }
    for t in 3..n + 1 {
        for i in 0..n - t + 1 {
            let j = i + t;
            for b in 0..3 {
                let mut ma = 0;
                if b <= 1 {
                    for k in 0..3 {
                        if s[i..i + k] == pon[..k] && s[j + k - 3..j] == pon[k..]
                        {
                            ma = max(ma, 1 + dp[i + k][j + k - 3][0]);
                        }
                    }
                }
                for c in 0..b + 1 {
                    for k in i + 1..j {
                        ma = max(ma, dp[i][k][c] + dp[k][j][b - c]);
                    }
                }
                if s[i] == 'p' && s[j - 1] == 'n' && b <= 1 {
                    for k in i + 1..j - 1 {
                        if s[k] == 'o' && dp[i + 1][k][0] >= 0 && dp[k + 1][j - 1][0] >= 0 {
                            ma = max(ma, 1 + dp[i + 1][k][0] + dp[k + 1][j - 1][0]);
                        }
                    }
                }
                ma = max(ma, dp[i][j - 1][b]);
                ma = max(ma, dp[i + 1][j][b]);
                dp[i][j][b] = ma;
            }
        }
    }
    println!("{}", max(-1, dp[0][n][2] - 2));
}
0