結果

問題 No.127 門松もどき
ユーザー koba-e964koba-e964
提出日時 2017-02-07 21:42:08
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,968 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 143,036 KB
実行使用メモリ 41,764 KB
最終ジャッジ日時 2023-08-26 05:24:58
合計ジャッジ時間 7,671 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn solve(a: &[(i32, usize)]) -> i32 {
    let n = a.len();
    let mut dp = vec![vec![0i32; n]; n];
    for i in 0 .. n {
        dp[i][a[i].1] = 1;
        for j in 0 .. i {
            if a[j].0 == a[i].0 { continue; }
            // >= a[j].1
            if a[i].1 > a[j].1 {
                for k in a[j].1 .. a[i].1 {
                    let tmp = dp[j][k] + 1;
                    let ret = &mut dp[i][a[j].1];
                    *ret = max(*ret, tmp);
                }
            } else {
                // <= a[j].1
                for k in a[i].1 + 1 .. a[j].1 + 1 {
                    let tmp = dp[j][k] + 1;
                    let ret = &mut dp[i][a[j].1];
                    *ret = max(*ret, tmp);
                }
            }
        }
    }
    *dp.iter().map(|w| w.iter().max().unwrap()).max().unwrap()
}

fn main() {
    let n = get();
    let mut a: Vec<(i32, usize)> = (0 .. n).map(|i| (get(), i)).collect();
    a.sort();
    a.reverse();
    let t2 = solve(&a);
    println!("{}", t2);
}
0