結果

問題 No.930 数列圧縮
ユーザー fukafukatanifukafukatani
提出日時 2019-11-22 23:18:16
言語 Rust
(1.44.1)
結果
WA   .
実行時間 -
コード長 2,347 Byte
コンパイル時間 1,283 ms
使用メモリ 8,460 KB
最終ジャッジ日時 2020-07-10 19:59:02

テストケース

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

ソースコード

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;
        }
        if v[next_pointer] == 0 {
            next_pointer += 1;
        }
        if v[prev_pointer] < v[next_pointer] {
            answers.push(v[prev_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