結果

問題 No.1017 Reiwa Sequence
ユーザー outlineoutline
提出日時 2021-01-13 06:53:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 2,057 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 136,800 KB
実行使用メモリ 33,152 KB
最終ジャッジ日時 2024-05-01 16:36:02
合計ジャッジ時間 34,993 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,144 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 5 ms
8,320 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,504 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 5 ms
10,240 KB
testcase_10 AC 42 ms
16,384 KB
testcase_11 AC 6 ms
9,660 KB
testcase_12 AC 280 ms
32,476 KB
testcase_13 AC 279 ms
32,352 KB
testcase_14 AC 7 ms
9,564 KB
testcase_15 AC 6 ms
10,112 KB
testcase_16 AC 6 ms
9,660 KB
testcase_17 AC 8 ms
11,464 KB
testcase_18 AC 6 ms
9,560 KB
testcase_19 AC 43 ms
16,384 KB
testcase_20 AC 44 ms
16,384 KB
testcase_21 AC 44 ms
16,384 KB
testcase_22 AC 43 ms
16,384 KB
testcase_23 AC 43 ms
16,384 KB
testcase_24 AC 44 ms
16,368 KB
testcase_25 AC 43 ms
16,384 KB
testcase_26 AC 42 ms
16,236 KB
testcase_27 AC 42 ms
16,384 KB
testcase_28 AC 41 ms
16,384 KB
testcase_29 AC 41 ms
16,384 KB
testcase_30 AC 42 ms
16,384 KB
testcase_31 AC 42 ms
16,292 KB
testcase_32 AC 41 ms
16,368 KB
testcase_33 AC 41 ms
16,456 KB
testcase_34 AC 42 ms
16,296 KB
testcase_35 AC 40 ms
16,380 KB
testcase_36 AC 41 ms
16,292 KB
testcase_37 AC 40 ms
16,404 KB
testcase_38 AC 41 ms
16,384 KB
testcase_39 AC 41 ms
16,428 KB
testcase_40 AC 293 ms
32,772 KB
testcase_41 AC 292 ms
32,708 KB
testcase_42 AC 304 ms
32,896 KB
testcase_43 AC 291 ms
32,856 KB
testcase_44 AC 286 ms
32,896 KB
testcase_45 AC 299 ms
32,768 KB
testcase_46 AC 299 ms
32,768 KB
testcase_47 AC 290 ms
32,896 KB
testcase_48 AC 299 ms
33,152 KB
testcase_49 AC 296 ms
33,152 KB
testcase_50 AC 299 ms
33,152 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 43 ms
16,384 KB
testcase_53 AC 42 ms
16,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];

    int m = min(n, 22);
    vector<int> sum(1 << m), cnt(150000 * m + 1);
    for(int mask = 0; mask < 1 << m; ++mask){
        for(int i = 0; i < m; ++i){
            if(mask >> i & 1)   sum[mask] += a[i];
        }
        cnt[sum[mask]] += 1;
    }

    int S = -1;
    for(int i = 1; i <= 150000 * m; ++i){
        if(cnt[i] > 1){
            S = i;
            break;
        }
    }
    if(S == -1){
        cout << "No\n";
        return 0;
    }

    int s = -1, t = -1;
    for(int mask = 0; mask < 1 << m; ++mask){
        if(sum[mask] != S)  continue;
        if(s == -1) s = mask;
        else    t = mask;
    }

    int andmask = s & t;
    s ^= andmask, t ^= andmask;

    for(int i = 0; i < m; ++i){
        if(s >> i & 1)  a[i] = a[i];
        else if(t >> i & 1) a[i] = -a[i];
        else    a[i] = 0;
    }
    for(int i = m; i < n; ++i)  a[i] = 0;

    cout << "Yes\n";
    for(int i = 0; i < n; ++i){
        cout << a[i] << (i == n - 1 ? '\n' : ' ');
    }

    return 0;
}
0