結果

問題 No.127 門松もどき
ユーザー koba-e964koba-e964
提出日時 2017-02-07 21:44:06
言語 Rust
(1.77.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,926 bytes
コンパイル時間 14,620 ms
コンパイル使用メモリ 402,612 KB
実行使用メモリ 37,376 KB
最終ジャッジ日時 2024-05-04 04:39:05
合計ジャッジ時間 20,940 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 TLE -
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 117 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2,051 ms
20,480 KB
testcase_13 AC 3,220 ms
26,880 KB
testcase_14 AC 2,829 ms
24,704 KB
testcase_15 AC 4,675 ms
33,664 KB
testcase_16 AC 2,647 ms
24,064 KB
testcase_17 AC 3,346 ms
27,520 KB
testcase_18 AC 2,510 ms
23,040 KB
testcase_19 AC 1,209 ms
14,848 KB
testcase_20 AC 1,271 ms
15,232 KB
testcase_21 AC 380 ms
7,936 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 3,625 ms
29,056 KB
testcase_25 AC 4,835 ms
33,920 KB
testcase_26 AC 1,610 ms
17,792 KB
権限があれば一括ダウンロードができます

ソースコード

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
            let mut ret = 1;
            if a[i].1 > a[j].1 {
                for k in a[j].1 .. a[i].1 {
                    let tmp = dp[j][k] + 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;
                    ret = max(ret, tmp);
                }
            }
            dp[i][a[j].1] = ret;
        }
    }
    *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