結果

問題 No.1017 Reiwa Sequence
ユーザー outlineoutline
提出日時 2021-01-13 06:53:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 2,057 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 135,664 KB
実行使用メモリ 33,052 KB
最終ジャッジ日時 2023-08-14 03:45:36
合計ジャッジ時間 20,443 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,924 KB
testcase_01 AC 3 ms
4,884 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
8,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
5,360 KB
testcase_06 AC 3 ms
4,944 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,524 KB
testcase_09 AC 5 ms
10,028 KB
testcase_10 AC 38 ms
16,220 KB
testcase_11 AC 4 ms
9,504 KB
testcase_12 AC 289 ms
32,396 KB
testcase_13 AC 289 ms
32,316 KB
testcase_14 AC 6 ms
9,576 KB
testcase_15 AC 5 ms
9,952 KB
testcase_16 AC 5 ms
9,372 KB
testcase_17 AC 7 ms
11,212 KB
testcase_18 AC 5 ms
9,492 KB
testcase_19 AC 42 ms
16,228 KB
testcase_20 AC 41 ms
16,240 KB
testcase_21 AC 43 ms
16,220 KB
testcase_22 AC 41 ms
16,228 KB
testcase_23 AC 40 ms
16,176 KB
testcase_24 AC 42 ms
16,364 KB
testcase_25 AC 40 ms
16,292 KB
testcase_26 AC 41 ms
16,292 KB
testcase_27 AC 41 ms
16,236 KB
testcase_28 AC 41 ms
16,232 KB
testcase_29 AC 41 ms
16,264 KB
testcase_30 AC 39 ms
16,160 KB
testcase_31 AC 41 ms
16,152 KB
testcase_32 AC 41 ms
16,224 KB
testcase_33 AC 40 ms
16,308 KB
testcase_34 AC 40 ms
16,164 KB
testcase_35 AC 39 ms
16,172 KB
testcase_36 AC 40 ms
16,308 KB
testcase_37 AC 40 ms
16,164 KB
testcase_38 AC 40 ms
16,108 KB
testcase_39 AC 39 ms
16,292 KB
testcase_40 AC 306 ms
32,648 KB
testcase_41 AC 303 ms
32,652 KB
testcase_42 AC 304 ms
32,520 KB
testcase_43 AC 303 ms
32,716 KB
testcase_44 AC 296 ms
32,596 KB
testcase_45 AC 302 ms
32,508 KB
testcase_46 AC 301 ms
32,528 KB
testcase_47 AC 301 ms
32,652 KB
testcase_48 AC 311 ms
32,912 KB
testcase_49 AC 304 ms
33,052 KB
testcase_50 AC 305 ms
32,904 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 40 ms
16,220 KB
testcase_53 AC 39 ms
16,220 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