結果

問題 No.1017 Reiwa Sequence
ユーザー fukafukatanifukafukatani
提出日時 2020-04-04 10:39:22
言語 Rust
(1.77.0)
結果
WA  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 2,201 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 155,128 KB
実行使用メモリ 107,220 KB
最終ジャッジ日時 2023-09-16 05:29:47
合計ジャッジ時間 26,388 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
104,988 KB
testcase_01 WA -
testcase_02 AC 48 ms
104,988 KB
testcase_03 WA -
testcase_04 AC 55 ms
104,984 KB
testcase_05 AC 71 ms
104,988 KB
testcase_06 AC 60 ms
104,992 KB
testcase_07 AC 54 ms
104,868 KB
testcase_08 AC 48 ms
105,072 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 295 ms
104,976 KB
testcase_36 AC 345 ms
105,052 KB
testcase_37 WA -
testcase_38 AC 287 ms
104,992 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 252 ms
106,384 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 333 ms
106,816 KB
testcase_50 AC 258 ms
107,220 KB
testcase_51 AC 40 ms
104,832 KB
testcase_52 WA -
testcase_53 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 get_idx(x: i64) -> usize {
    (x + 11 * 150000) as usize
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let a = a.into_iter().take(22).collect::<Vec<_>>();

    let mut dp = vec![None; 2 * 11 * 150000 + 1];

    for i in 0..a.len() {
        for prev in -11 * 150000..11 * 150000 + 1 {
            if dp[get_idx(prev)] == None {
                continue;
            }
            let cand = prev + a[i];
            if cand < 11 * 150000 && dp[get_idx(cand)] == None {
                dp[get_idx(cand)] = Some((Some(prev), i, 1));
            }
            let cand = prev - a[i];
            if cand > (-11 * 150000) && dp[get_idx(cand)] == None {
                dp[get_idx(cand)] = Some((Some(prev), i, -1));
            }
        }
        if dp[get_idx(a[i])] == None {
            dp[get_idx(a[i])] = Some((None, i, 1));
        }
        if dp[get_idx(-a[i])] == None {
            dp[get_idx(-a[i])] = Some((None, i, -1));
        }
    }

    if dp[get_idx(0)] == None {
        println!("No");
    } else {
        println!("Yes");
        let mut answers = vec![0i64; n];
        let mut cur = 0;
        loop {
            let (prev, i, sign) = dp[get_idx(cur)].unwrap();
            answers[i] = a[i] * sign;
            if let Some(p) = prev {
                cur = p;
            } else {
                break;
            }
        }
        for i in 0..n - 1 {
            print!("{} ", answers[i]);
        }
        println!("{}", answers[n - 1]);
    }
}

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