結果

問題 No.1017 Reiwa Sequence
ユーザー やむなくやむなく
提出日時 2020-04-03 22:26:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 3,718 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 180,916 KB
実行使用メモリ 13,532 KB
最終ジャッジ日時 2023-09-16 03:09:07
合計ジャッジ時間 18,253 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 401 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 32 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 44 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 246 ms
4,380 KB
testcase_15 AC 249 ms
4,380 KB
testcase_16 AC 245 ms
4,380 KB
testcase_17 AC 238 ms
4,380 KB
testcase_18 AC 245 ms
4,384 KB
testcase_19 AC 219 ms
4,380 KB
testcase_20 AC 219 ms
4,376 KB
testcase_21 AC 220 ms
4,376 KB
testcase_22 AC 219 ms
4,380 KB
testcase_23 AC 217 ms
4,376 KB
testcase_24 AC 220 ms
4,376 KB
testcase_25 AC 218 ms
4,376 KB
testcase_26 AC 218 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 26 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 106 ms
4,376 KB
testcase_33 AC 55 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 68 ms
9,692 KB
testcase_41 AC 68 ms
9,640 KB
testcase_42 AC 65 ms
9,428 KB
testcase_43 AC 66 ms
9,568 KB
testcase_44 AC 67 ms
9,588 KB
testcase_45 AC 66 ms
9,712 KB
testcase_46 AC 66 ms
9,264 KB
testcase_47 AC 66 ms
9,360 KB
testcase_48 AC 16 ms
6,400 KB
testcase_49 AC 114 ms
13,532 KB
testcase_50 AC 16 ms
6,556 KB
testcase_51 AC 816 ms
4,380 KB
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by yamunaku on 2020/04/03.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

unsigned long long xor128(){
    static unsigned long long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long long t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int main(){
    //CFS;
    int n;
    cin >> n;
    map<int, int> mp;
    vi a(n);
    vector<pair<ll, int>> p(n);
    bitset<150001> bit;
    rep(i, n){
        cin >> a[i];
        p[i] = {a[i], i};
        bit.set(a[i]);
        auto itr = mp.find(a[i]);
        if(itr != mp.end()){
            CYES;
            vi ans(n, 0);
            ans[i] = a[i], ans[itr->second] = -a[i];
            rep(j, n){
                cout << ans[j] << " ";
            }
            cout << endl;
            return 0;
        }
        mp[a[i]] = i;
    }
    rep(i, n){
        bit.reset(a[i]);
        if((bit & (bit << a[i])).any()){
            bitset<150001> bit2 = bit & (bit << a[i]);
            rep(j, 150001){
                if(bit2.test(j)){
                    vi ans(n, 0);
                    ans[i] = a[i];
                    ans[mp.find(j)->second] = -j;
                    ans[mp.find(j - a[i])->second] = j - a[i];
                    CYES;
                    rep(k, n){
                        cout << ans[k] << " ";
                    }
                    cout << endl;
                    return 0;
                }
            }
        }
        bit.set(a[i]);
    }
    vi tmp;
    int kk = 1e7 / n;
    rep(t, kk){
        ll sum = 0;
        tmp = vi(n, 0);
        bool ok = false;
        rep(i, n){
            tmp[i] = xor128() % 3 - 1;
            if(tmp[i] != 0) ok = true;
            sum += tmp[i] * p[i].first;
        }
        if(ok) if(sum == 0) goto next;
    }
    rep(t, kk){
        rep(i, n / 2){
            swap(p[xor128() % n], p[xor128() % n]);
        }
        ll sum = 0;
        tmp = vi(n, 0);
        repl(i, xor128() % n, n){
            if(sum > 0){
                if(sum - p[i].first == 0){
                    tmp[i] = -1;
                    goto next;
                }else{
                    if(xor128() % 2){
                        tmp[i] = -1;
                        sum -= p[i].first;
                    }
                }
            }else{
                if(sum + p[i].first == 0){
                    tmp[i] = 1;
                    goto next;
                }else{
                    if(xor128() % 2){
                        tmp[i] = 1;
                        sum += p[i].first;
                    }
                }
            }
        }
    }
    CNO;
    return 0;
    next:;
    CYES;
    vi ans(n, 0);
    rep(i, n){
        ans[p[i].second] = tmp[i] * p[i].first;
    }
    rep(i, n){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}
0