結果

問題 No.930 数列圧縮
ユーザー fukafukatanifukafukatani
提出日時 2019-11-22 23:20:06
言語 Rust
(1.44.1)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,391 Byte
コンパイル時間 1,051 ms
使用メモリ 8,444 KB
最終ジャッジ日時 2020-05-24 13:13:22

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
980 KB
testcase_01 AC 1 ms
984 KB
testcase_02 AC 1 ms
980 KB
testcase_03 AC 1 ms
976 KB
testcase_04 AC 2 ms
980 KB
testcase_05 AC 2 ms
976 KB
testcase_06 AC 1 ms
984 KB
testcase_07 AC 2 ms
1,052 KB
testcase_08 AC 14 ms
6,084 KB
testcase_09 AC 16 ms
6,972 KB
testcase_10 AC 14 ms
5,540 KB
testcase_11 AC 14 ms
6,104 KB
testcase_12 AC 17 ms
6,976 KB
testcase_13 AC 4 ms
1,492 KB
testcase_14 AC 4 ms
1,564 KB
testcase_15 AC 19 ms
8,444 KB
testcase_16 AC 19 ms
8,444 KB
testcase_17 AC 20 ms
8,440 KB
testcase_18 AC 20 ms
8,444 KB
testcase_19 AC 20 ms
8,440 KB
testcase_20 AC 21 ms
8,444 KB
testcase_21 AC 20 ms
8,444 KB
testcase_22 AC 1 ms
984 KB
testcase_23 AC 19 ms
8,444 KB
testcase_24 AC 1 ms
980 KB
testcase_25 AC 1 ms
988 KB
testcase_26 AC 1 ms
984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut v = read_vec::<usize>();
    if v[0] > v[v.len() - 1] {
        println!("No");
        return;
    }
    println!("Yes");
    let mut prev_pointer = 1;
    let mut next_pointer = 2;
    let mut answers = vec![];
    while next_pointer < n - 1 {
        if prev_pointer >= next_pointer {
            next_pointer += 1;
            continue;
        }
        if v[prev_pointer] == 0 {
            prev_pointer += 1;
            continue;
        }
        if v[next_pointer] == 0 {
            next_pointer += 1;
            continue;
        }
        if v[prev_pointer] < v[next_pointer] {
            answers.push(v[next_pointer]);
            v[next_pointer] = 0;
            next_pointer += 1;
        } else {
            prev_pointer += 1;
        }
    }
    debug!(v);

    let mut pointer = 1;
    while pointer < n - 1 {
        if v[pointer] == 0 {
            pointer += 1;
            continue;
        }
        if v[pointer] < v[0] {
            break;
        }
        answers.push(v[pointer]);
        v[pointer] = 0;
        pointer += 1;
    }
    let mut pointer = n - 2;
    while pointer > 0 {
        if v[pointer] == 0 {
            pointer -= 1;
            continue;
        }
        if v[pointer] > v[n - 1] {
            break;
        }
        answers.push(v[pointer]);
        v[pointer] = 0;
        pointer -= 1;
    }
    debug!(v);
    answers.push(v[0]);
    print_array(&answers);
}

fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

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