結果

問題 No.1017 Reiwa Sequence
ユーザー kyort0nkyort0n
提出日時 2020-04-04 05:02:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,360 ms / 2,000 ms
コード長 1,650 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 181,556 KB
実行使用メモリ 107,372 KB
最終ジャッジ日時 2023-09-26 23:01:57
合計ジャッジ時間 30,845 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 11 ms
4,712 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 23 ms
6,172 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 1,209 ms
107,320 KB
testcase_20 AC 1,329 ms
107,356 KB
testcase_21 AC 1,360 ms
107,356 KB
testcase_22 AC 1,347 ms
107,316 KB
testcase_23 AC 1,312 ms
107,280 KB
testcase_24 AC 1,347 ms
107,372 KB
testcase_25 AC 1,262 ms
107,272 KB
testcase_26 AC 964 ms
107,280 KB
testcase_27 AC 575 ms
54,380 KB
testcase_28 AC 116 ms
15,604 KB
testcase_29 AC 9 ms
4,440 KB
testcase_30 AC 600 ms
54,044 KB
testcase_31 AC 31 ms
7,076 KB
testcase_32 AC 554 ms
53,992 KB
testcase_33 AC 452 ms
53,988 KB
testcase_34 AC 508 ms
53,972 KB
testcase_35 AC 496 ms
53,888 KB
testcase_36 AC 506 ms
53,972 KB
testcase_37 AC 591 ms
53,876 KB
testcase_38 AC 593 ms
54,032 KB
testcase_39 AC 589 ms
54,060 KB
testcase_40 AC 28 ms
5,996 KB
testcase_41 AC 28 ms
6,100 KB
testcase_42 AC 27 ms
6,116 KB
testcase_43 AC 27 ms
6,008 KB
testcase_44 AC 23 ms
6,008 KB
testcase_45 AC 27 ms
5,884 KB
testcase_46 AC 27 ms
5,888 KB
testcase_47 AC 27 ms
5,888 KB
testcase_48 AC 43 ms
7,752 KB
testcase_49 AC 31 ms
7,756 KB
testcase_50 AC 33 ms
7,872 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 878 ms
85,136 KB
testcase_53 AC 879 ms
85,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
map<ll, vector<ll>> mp;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N), ans(N);
    vector<l_l> v(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        v[i] = {A[i], i};
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < (1LL << min(N, 30LL)); i++) {
        ll sum = 0;
        for(int j = 0; j <= min(N, 30LL); j++) {
            if(i & (1 << j)) sum += v[j].first;
        }
        if(mp.count(sum)) {
            for(int j = 0; j <= min(N, 30LL); j++) {
                if(i & (1 << j)) ans[v[j].second] += v[j].first;
            }
            for(auto tmp : mp[sum]) {
                ans[tmp] -= A[tmp];
            }
            cout << "Yes" << endl;
            for(int i = 0; i < N; i++) {
                if(i != 0) cout << " ";
                cout << ans[i];
            }
            cout << endl;
            return 0;
        } else {
            for(int j = 0; j <= min(N, 30LL); j++) {
                if(i & (1 << j)) mp[sum].push_back(v[j].second);
            }
        }
    }
    cout << "No" << endl;
    return 0;
}
0