結果

問題 No.1188 レベルX門松列
ユーザー nebocconebocco
提出日時 2020-08-22 15:09:14
言語 Rust
(1.77.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 4,050 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 161,024 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-23 09:31:41
合計ジャッジ時間 2,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,144 KB
testcase_01 AC 21 ms
5,504 KB
testcase_02 AC 21 ms
5,376 KB
testcase_03 AC 28 ms
6,144 KB
testcase_04 AC 10 ms
6,264 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 5 ms
5,632 KB
testcase_07 AC 13 ms
6,144 KB
testcase_08 AC 13 ms
6,144 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 17 ms
5,376 KB
testcase_15 AC 28 ms
6,528 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 22 ms
5,504 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 20 ms
5,376 KB
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(dead_code, unused_mut, unused_macros)]
#![allow(non_snake_case)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules ! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }
macro_rules ! min {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: min ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: min ($ a , min ! ($ ($ rest ) ,+ ) ) } } ; }
macro_rules ! chmin {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_min = min ! ($ ($ cmps ) ,+ ) ; if $ base > cmp_min {$ base = cmp_min ; true } else {false } } } ; }
macro_rules ! chmax {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_max = max ! ($ ($ cmps ) ,+ ) ; if $ base < cmp_max {$ base = cmp_max ; true } else {false } } } ; }

const MOD: usize = 998244353;

fn lds(a: &Vec<u32>) -> Vec<usize> {
    let n = a.len();
    let mut res = vec![0; n];
    let mut st = Vec::new();
    for i in 0..n {
        if st.last().unwrap_or(&1_000_000_001) > &a[i] {
            res[i] = st.len();
            st.push(a[i]);
        } else {
            let mut ok: i32 = -1 ;
            let mut ng: i32 = st.len() as i32;
            while ng - ok > 1 {
                let mid = (ok + ng) as usize / 2;
                if st[mid] > a[i] {
                    ok = mid as i32;
                } else {
                    ng = mid as i32;
                }
            }
            res[i] = ng as usize;
            st[ng as usize] = a[i];
        }
    }
    res
}

fn lis(a: &Vec<u32>) -> Vec<usize> {
    let n = a.len();
    let mut res = vec![0; n];
    let mut st = Vec::new();
    for i in 0..n {
        if st.last().unwrap_or(&0) < &a[i] {
            res[i] = st.len();
            st.push(a[i]);
        } else {
            let mut ok: i32 = -1 ;
            let mut ng: i32 = st.len() as i32;
            while ng - ok > 1 {
                let mid = (ok + ng) as usize / 2;
                if st[mid] < a[i] {
                    ok = mid as i32;
                } else {
                    ng = mid as i32;
                }
            }
            res[i] = ng as usize;
            st[ng as usize] = a[i];
        }
    }
    res
}

use std::cmp::min;

fn main() {
    input!{
        n:usize,
        a:[u32; n]
    }
    let mut a = a;
    let ne = lis(&a);
    let se = lds(&a);
    a.reverse();
    let mut nw = lis(&a);
    nw.reverse();
    let mut sw = lds(&a);
    sw.reverse();
    let mut ans = 0;
    // println!("{:?}", ne);
    // println!("{:?}", nw);
    // println!("{:?}", se);
    // println!("{:?}", sw);
    for i in 0..n {
        chmax!(ans, min(ne[i], nw[i]));
        chmax!(ans, min(se[i], sw[i]));
    }
    println!("{}", ans);
}
0