結果

問題 No.1017 Reiwa Sequence
ユーザー hiro71687khiro71687k
提出日時 2023-03-02 17:59:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 470 ms / 2,000 ms
コード長 1,515 bytes
コンパイル時間 4,944 ms
コンパイル使用メモリ 275,008 KB
実行使用メモリ 171,096 KB
最終ジャッジ日時 2023-10-17 14:16:08
合計ジャッジ時間 49,279 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
97,040 KB
testcase_01 AC 40 ms
97,072 KB
testcase_02 AC 38 ms
97,072 KB
testcase_03 AC 39 ms
97,072 KB
testcase_04 AC 38 ms
97,072 KB
testcase_05 AC 39 ms
97,072 KB
testcase_06 AC 39 ms
97,072 KB
testcase_07 AC 39 ms
97,072 KB
testcase_08 AC 38 ms
97,168 KB
testcase_09 AC 39 ms
97,168 KB
testcase_10 AC 41 ms
97,432 KB
testcase_11 AC 39 ms
97,168 KB
testcase_12 AC 43 ms
97,696 KB
testcase_13 AC 38 ms
97,168 KB
testcase_14 AC 39 ms
97,168 KB
testcase_15 AC 40 ms
97,432 KB
testcase_16 AC 38 ms
97,168 KB
testcase_17 AC 47 ms
98,752 KB
testcase_18 AC 39 ms
97,168 KB
testcase_19 AC 375 ms
158,416 KB
testcase_20 AC 377 ms
158,416 KB
testcase_21 AC 379 ms
158,416 KB
testcase_22 AC 376 ms
158,416 KB
testcase_23 AC 366 ms
158,416 KB
testcase_24 AC 362 ms
158,416 KB
testcase_25 AC 354 ms
158,416 KB
testcase_26 AC 346 ms
158,416 KB
testcase_27 AC 256 ms
135,448 KB
testcase_28 AC 289 ms
142,312 KB
testcase_29 AC 48 ms
98,224 KB
testcase_30 AC 51 ms
99,544 KB
testcase_31 AC 79 ms
104,032 KB
testcase_32 AC 197 ms
126,736 KB
testcase_33 AC 42 ms
97,960 KB
testcase_34 AC 205 ms
126,736 KB
testcase_35 AC 38 ms
97,168 KB
testcase_36 AC 39 ms
97,168 KB
testcase_37 AC 204 ms
126,736 KB
testcase_38 AC 38 ms
97,168 KB
testcase_39 AC 205 ms
126,736 KB
testcase_40 AC 470 ms
171,096 KB
testcase_41 AC 466 ms
170,832 KB
testcase_42 AC 457 ms
170,304 KB
testcase_43 AC 459 ms
170,568 KB
testcase_44 AC 127 ms
109,320 KB
testcase_45 AC 470 ms
170,832 KB
testcase_46 AC 450 ms
170,568 KB
testcase_47 AC 434 ms
170,304 KB
testcase_48 AC 186 ms
117,240 KB
testcase_49 AC 187 ms
116,976 KB
testcase_50 AC 188 ms
116,976 KB
testcase_51 AC 38 ms
97,112 KB
testcase_52 AC 359 ms
157,888 KB
testcase_53 AC 112 ms
111,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.14159265359;
ll inf=10000000000000001;
ll mod=1000000007;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    bool ok=false;
    ll x=min(n,(ll)23);
    vector<vector<vector<ll>>>memo(4000000);
    vector<ll>two(25,1);
    for (ll i = 1; i < two.size(); i++)
    {
        two[i]=two[i-1]*2;
    }
    ll ans=-1;
    for (ll i = 1; i < two[x]; i++)
    {
        ll y=0;
        vector<ll>b;
        for (ll j = 0; j < x; j++)
        {
            if (two[j]&i)
            {
                y+=a[j];
                b.push_back(j);
            }
        }
        if (memo[y].size()>=1)
        {
            ok=true;
            ans=y;
            memo[y].push_back(b);
            break;
        }else{
            memo[y].push_back(b);
        }
    }
    if (ans==-1)
    {
        cout << "No" << endl;
        return 0;
    }
    map<ll,ll>b,c;
    for (ll i = 0; i < memo[ans][0].size(); i++)
    {
        b[memo[ans][0][i]]+=1;
    }
    for (ll i = 0; i < memo[ans][1].size(); i++)
    {
        c[memo[ans][1][i]]+=1;
    }
    cout << "Yes" << endl;
    for (ll i = 0; i < n; i++)
    {
        if (b[i]>=1)
        {
            cout << a[i] << ' ';
        }else if (c[i]>=1)
        {
            cout << -a[i] << ' ';
        }else{
            cout << 0 << ' ';
        }
    }
}
0