結果

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

テストケース

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