結果

問題 No.1188 レベルX門松列
ユーザー fukafukatanifukafukatani
提出日時 2020-08-23 14:38:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,650 bytes
コンパイル時間 4,541 ms
コンパイル使用メモリ 157,056 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 17:45:20
合計ジャッジ時間 2,696 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
5,248 KB
testcase_01 AC 29 ms
5,376 KB
testcase_02 AC 25 ms
5,376 KB
testcase_03 AC 35 ms
5,376 KB
testcase_04 AC 39 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 34 ms
5,376 KB
testcase_08 AC 35 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 21 ms
5,376 KB
testcase_15 AC 35 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 28 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 AC 26 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;

fn solve(a: &Vec<i64>) -> Vec<usize> {
    let n = a.len();
    let mut dp = vec![std::i64::MAX; n];
    let mut from_right_pos = vec![0; n];
    for i in 0..n {
        let pointer = dp.lower_bound(&a[i]);
        dp[pointer] = a[i];
        from_right_pos[i] = dp.lower_bound(&std::i64::MAX);
    }
    from_right_pos
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<i64>();

    let mut ans = 0;
    for _ in 0..2 {
        let temp1 = solve(&a);
        a.reverse();
        let mut temp2 = solve(&a);
        temp2.reverse();
        a.reverse();
        for i in 0..n {
            ans = max(ans, min(temp1[i], temp2[i]) - 1);
        }
        a = a.iter().map(|&x| -x).collect::<Vec<_>>();
    }

    println!("{}", ans);
}

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()
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}
0