結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 9 ms
11,500 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 22 ms
16,752 KB
testcase_15 AC 23 ms
17,436 KB
testcase_16 AC 22 ms
16,744 KB
testcase_17 AC 27 ms
18,804 KB
testcase_18 AC 22 ms
17,028 KB
testcase_19 AC 29 ms
21,520 KB
testcase_20 AC 29 ms
21,620 KB
testcase_21 AC 30 ms
21,516 KB
testcase_22 AC 32 ms
21,624 KB
testcase_23 AC 32 ms
21,584 KB
testcase_24 AC 33 ms
21,560 KB
testcase_25 AC 33 ms
21,552 KB
testcase_26 AC 33 ms
21,564 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 WA -
testcase_50 WA -
testcase_51 AC 6 ms
10,412 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());

    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;
    }

    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