結果

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

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
in01.txt WA -
in02.txt WA -
in03.txt WA -
in04.txt WA -
in05.txt WA -
in06.txt WA -
in07.txt AC 1 ms
964 KB
in08.txt WA -
in09.txt WA -
in10.txt WA -
in11.txt WA -
in12.txt WA -
in13.txt WA -
in14.txt AC 4 ms
1,504 KB
in15.txt AC 5 ms
1,572 KB
in16.txt WA -
in17.txt AC 20 ms
8,452 KB
in18.txt WA -
in19.txt WA -
in20.txt WA -
in21.txt WA -
in22.txt WA -
in23.txt AC 2 ms
964 KB
in24.txt AC 21 ms
8,456 KB
sample01.txt AC 2 ms
964 KB
sample02.txt AC 1 ms
964 KB
sample03.txt 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