結果

問題 No.1017 Reiwa Sequence
ユーザー fukafukatanifukafukatani
提出日時 2020-04-03 23:07:28
言語 Rust
(1.77.0 + proconio)
結果
TLE  
実行時間 -
コード長 2,861 bytes
コンパイル時間 12,059 ms
コンパイル使用メモリ 405,740 KB
実行使用メモリ 294,332 KB
最終ジャッジ日時 2024-07-03 05:43:29
合計ジャッジ時間 35,300 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 4 ms
5,504 KB
testcase_02 AC 3 ms
5,504 KB
testcase_03 AC 4 ms
6,016 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,504 KB
testcase_07 AC 5 ms
5,504 KB
testcase_08 AC 3 ms
5,504 KB
testcase_09 AC 81 ms
41,504 KB
testcase_10 AC 1,159 ms
294,220 KB
testcase_11 AC 36 ms
23,496 KB
testcase_12 AC 1,893 ms
294,112 KB
testcase_13 AC 1,466 ms
294,148 KB
testcase_14 AC 35 ms
23,492 KB
testcase_15 AC 91 ms
41,668 KB
testcase_16 AC 34 ms
23,456 KB
testcase_17 AC 402 ms
149,828 KB
testcase_18 AC 35 ms
23,492 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 1,823 ms
294,168 KB
testcase_25 AC 1,826 ms
294,264 KB
testcase_26 AC 1,634 ms
294,332 KB
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 AC 1,919 ms
294,180 KB
testcase_31 AC 1,873 ms
294,096 KB
testcase_32 AC 1,493 ms
294,100 KB
testcase_33 AC 899 ms
149,864 KB
testcase_34 AC 4 ms
6,944 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 5 ms
6,940 KB
testcase_37 AC 1,771 ms
294,196 KB
testcase_38 AC 1,730 ms
294,216 KB
testcase_39 AC 1,783 ms
294,264 KB
testcase_40 AC 22 ms
10,936 KB
testcase_41 AC 23 ms
10,872 KB
testcase_42 AC 21 ms
10,832 KB
testcase_43 AC 24 ms
10,576 KB
testcase_44 AC 22 ms
10,704 KB
testcase_45 AC 22 ms
10,984 KB
testcase_46 AC 22 ms
10,680 KB
testcase_47 AC 21 ms
10,836 KB
testcase_48 AC 34 ms
11,076 KB
testcase_49 AC 31 ms
13,672 KB
testcase_50 AC 22 ms
8,832 KB
testcase_51 AC 4 ms
6,944 KB
testcase_52 AC 1,826 ms
294,172 KB
testcase_53 AC 1,791 ms
294,272 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 yes(a: &Vec<i64>) {
    println!("Yes");
    for &num in a.iter().take(a.len() - 1) {
        print!("{} ", num);
    }
    println!("{}", a[a.len() - 1]);
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();

    let mut poses = vec![vec![]; 150001];
    for (i, &num) in a.iter().enumerate() {
        poses[num].push(i);
    }

    for i in 0..150001 {
        if poses[i].len() >= 2 {
            let mut answers = vec![0; n];
            answers[poses[i][0]] = i as i64;
            answers[poses[i][1]] = -(i as i64);
            yes(&answers);
            return;
        }
    }

    let max_search = 20;
    let mut cand_pos = vec![];
    let mut cand_num = vec![];
    for i in 0..150001 {
        if poses[i].len() == 1 {
            cand_num.push(i as i64);
            cand_pos.push(poses[i][0]);
        }
        if cand_num.len() == max_search {
            break;
        }
    }

    let mut dp = HashSet::new();
    let mut from = HashMap::new();

    for i in 0..cand_num.len() {
        let clone = dp.clone();
        for num in clone {
            if !dp.contains(&(cand_num[i] + num)) {
                from.insert(cand_num[i] + num, (Some(num), i, 1));
                dp.insert(cand_num[i] + num);
            }
            if !dp.contains(&(-cand_num[i] + num)) {
                from.insert(-cand_num[i] + num, (Some(num), i, -1));
                dp.insert(-cand_num[i] + num);
            }
        }
        if !dp.contains(&cand_num[i]) {
            dp.insert(cand_num[i]);
            from.insert(cand_num[i], (None, i, 1));
        }
        if !dp.contains(&(-cand_num[i])) {
            dp.insert(-cand_num[i]);
            from.insert(-cand_num[i], (None, i, -1));
        }
    }
    if dp.contains(&0) {
        let mut cur = 0;
        let mut answers = vec![0; n];
        loop {
            let (prev, idx, sign) = from[&cur];
            let i = cand_pos[idx];
            answers[i] = a[i] as i64 * sign;
            if let Some(p) = prev {
                cur = p;
            } else {
                break;
            }
        }
        yes(&answers);
    } else {
        println!("No");
    }
}

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