結果

問題 No.1017 Reiwa Sequence
ユーザー qLethonqLethon
提出日時 2020-04-03 22:19:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,145 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 209,212 KB
実行使用メモリ 22,700 KB
最終ジャッジ日時 2023-09-16 02:33:07
合計ジャッジ時間 14,505 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
12,932 KB
testcase_01 AC 10 ms
11,568 KB
testcase_02 AC 8 ms
10,784 KB
testcase_03 AC 17 ms
15,584 KB
testcase_04 AC 8 ms
10,816 KB
testcase_05 AC 12 ms
12,156 KB
testcase_06 AC 10 ms
11,572 KB
testcase_07 AC 8 ms
10,820 KB
testcase_08 AC 8 ms
10,832 KB
testcase_09 AC 22 ms
17,368 KB
testcase_10 AC 32 ms
21,584 KB
testcase_11 AC 22 ms
16,980 KB
testcase_12 AC 31 ms
21,640 KB
testcase_13 AC 32 ms
21,368 KB
testcase_14 AC 21 ms
16,716 KB
testcase_15 AC 23 ms
17,488 KB
testcase_16 AC 22 ms
16,904 KB
testcase_17 AC 26 ms
18,688 KB
testcase_18 AC 22 ms
17,040 KB
testcase_19 AC 29 ms
21,804 KB
testcase_20 AC 28 ms
21,520 KB
testcase_21 AC 29 ms
21,644 KB
testcase_22 AC 30 ms
21,612 KB
testcase_23 AC 31 ms
21,576 KB
testcase_24 AC 31 ms
21,756 KB
testcase_25 AC 33 ms
21,564 KB
testcase_26 AC 31 ms
21,456 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 31 ms
21,456 KB
testcase_30 AC 30 ms
21,540 KB
testcase_31 AC 31 ms
21,572 KB
testcase_32 WA -
testcase_33 AC 31 ms
21,532 KB
testcase_34 WA -
testcase_35 AC 32 ms
21,564 KB
testcase_36 AC 31 ms
21,584 KB
testcase_37 WA -
testcase_38 AC 32 ms
21,524 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 64 ms
22,108 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 84 ms
22,620 KB
testcase_49 AC 86 ms
22,700 KB
testcase_50 AC 85 ms
22,624 KB
testcase_51 AC 6 ms
10,364 KB
testcase_52 WA -
testcase_53 AC 31 ms
21,524 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;
    n = min(n, 18);
    const constexpr int upper = 18 * 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