結果

問題 No.1017 Reiwa Sequence
ユーザー qLethonqLethon
提出日時 2020-04-03 22:23:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,298 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 211,744 KB
実行使用メモリ 26,140 KB
最終ジャッジ日時 2023-09-16 02:41:06
合計ジャッジ時間 15,395 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
14,128 KB
testcase_01 AC 11 ms
12,360 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 25 ms
18,224 KB
testcase_15 AC 25 ms
19,152 KB
testcase_16 AC 26 ms
18,564 KB
testcase_17 AC 31 ms
20,472 KB
testcase_18 AC 25 ms
18,540 KB
testcase_19 AC 37 ms
24,660 KB
testcase_20 AC 35 ms
24,128 KB
testcase_21 AC 38 ms
24,096 KB
testcase_22 AC 39 ms
24,236 KB
testcase_23 AC 39 ms
24,424 KB
testcase_24 AC 40 ms
24,472 KB
testcase_25 AC 39 ms
24,296 KB
testcase_26 AC 38 ms
24,348 KB
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 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 96 ms
26,140 KB
testcase_50 WA -
testcase_51 AC 7 ms
11,100 KB
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

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());
    sort(A.begin(), A.end());
    if (unique(A.begin(), A.end()) != A.end()){
        puts("Yes");
        return 0;
    }

    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