結果

問題 No.1017 Reiwa Sequence
ユーザー qLethonqLethon
提出日時 2020-04-03 22:24:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 209,452 KB
実行使用メモリ 26,368 KB
最終ジャッジ日時 2023-09-16 03:03:43
合計ジャッジ時間 14,754 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
14,156 KB
testcase_01 AC 11 ms
12,672 KB
testcase_02 AC 8 ms
11,940 KB
testcase_03 AC 21 ms
16,900 KB
testcase_04 AC 10 ms
11,828 KB
testcase_05 AC 13 ms
13,392 KB
testcase_06 AC 11 ms
12,728 KB
testcase_07 AC 8 ms
11,872 KB
testcase_08 AC 9 ms
11,948 KB
testcase_09 AC 25 ms
19,336 KB
testcase_10 AC 38 ms
24,588 KB
testcase_11 AC 24 ms
18,540 KB
testcase_12 AC 40 ms
24,996 KB
testcase_13 AC 38 ms
25,060 KB
testcase_14 AC 24 ms
18,468 KB
testcase_15 AC 26 ms
19,260 KB
testcase_16 AC 25 ms
18,216 KB
testcase_17 AC 31 ms
20,648 KB
testcase_18 AC 24 ms
18,472 KB
testcase_19 AC 35 ms
24,212 KB
testcase_20 AC 34 ms
24,092 KB
testcase_21 AC 36 ms
24,540 KB
testcase_22 AC 37 ms
24,132 KB
testcase_23 AC 38 ms
24,092 KB
testcase_24 AC 38 ms
24,144 KB
testcase_25 AC 38 ms
24,092 KB
testcase_26 AC 38 ms
24,136 KB
testcase_27 AC 39 ms
24,468 KB
testcase_28 AC 39 ms
24,420 KB
testcase_29 AC 39 ms
24,640 KB
testcase_30 AC 39 ms
24,412 KB
testcase_31 AC 38 ms
24,148 KB
testcase_32 AC 38 ms
24,400 KB
testcase_33 AC 36 ms
24,280 KB
testcase_34 AC 38 ms
24,144 KB
testcase_35 AC 36 ms
24,344 KB
testcase_36 AC 37 ms
24,584 KB
testcase_37 AC 38 ms
24,656 KB
testcase_38 AC 39 ms
24,084 KB
testcase_39 AC 38 ms
24,084 KB
testcase_40 AC 68 ms
25,892 KB
testcase_41 AC 67 ms
25,924 KB
testcase_42 AC 68 ms
25,668 KB
testcase_43 AC 73 ms
25,648 KB
testcase_44 AC 72 ms
25,728 KB
testcase_45 AC 72 ms
25,648 KB
testcase_46 AC 71 ms
25,716 KB
testcase_47 AC 70 ms
25,548 KB
testcase_48 AC 92 ms
26,196 KB
testcase_49 AC 91 ms
26,368 KB
testcase_50 AC 93 ms
26,084 KB
testcase_51 AC 6 ms
11,156 KB
testcase_52 AC 38 ms
24,152 KB
testcase_53 AC 39 ms
24,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int64_t> A(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());

    int m = n;
    const constexpr int k = 20;
    n = min(n, k);
    const constexpr int upper = k * 150000;
    vector<bitset<2 * upper + 1>> DP(n + 1);
    bitset<2 * upper + 1> zero;
    zero.set(upper);
    for (int i = 0; i < n; i++){
        DP[i + 1] = (zero << A[i]) | (zero >> A[i]) | (DP[i] << A[i]) | (DP[i] >> A[i]) | DP[i];
    }
    if (!DP[n][upper]){
        puts("No");
        return 0;
    }

    puts("Yes");
    for (int i = 0; i < n; i++)
        DP[i].set(upper);
    vector<int> ans;
    int pos = upper;
    for (int i = n - 1; i >= 0; i--){
        if (DP[i][pos + A[i]]){
            ans.push_back(-1);
            pos += A[i];
        }
        else if(DP[i][pos - A[i]]){
            ans.push_back(1);
            pos -= A[i];
        }
        else
            ans.push_back(0);
    }

    reverse(ans.begin(), ans.end());
    for (int i = 0; i < n; i++)
        cout << A[i] * ans[i] << " ";
    
    for (int i = n; i < m; i++)
        cout << 0 << " ";
    cout << endl;
}
0