結果

問題 No.1017 Reiwa Sequence
ユーザー ShibuyapShibuyap
提出日時 2020-07-26 02:33:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 618 ms / 2,000 ms
コード長 1,417 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 209,116 KB
実行使用メモリ 78,764 KB
最終ジャッジ日時 2023-09-10 02:59:03
合計ジャッジ時間 19,953 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,388 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 8 ms
5,120 KB
testcase_13 AC 4 ms
4,384 KB
testcase_14 AC 3 ms
4,508 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 10 ms
5,612 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 618 ms
71,012 KB
testcase_20 AC 555 ms
70,932 KB
testcase_21 AC 580 ms
71,208 KB
testcase_22 AC 544 ms
70,936 KB
testcase_23 AC 522 ms
70,916 KB
testcase_24 AC 543 ms
70,928 KB
testcase_25 AC 465 ms
70,936 KB
testcase_26 AC 391 ms
70,984 KB
testcase_27 AC 88 ms
17,888 KB
testcase_28 AC 114 ms
21,368 KB
testcase_29 AC 51 ms
12,808 KB
testcase_30 AC 19 ms
7,320 KB
testcase_31 AC 42 ms
11,932 KB
testcase_32 AC 41 ms
11,748 KB
testcase_33 AC 5 ms
4,424 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 196 ms
36,644 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 1 ms
4,384 KB
testcase_38 AC 229 ms
36,680 KB
testcase_39 AC 19 ms
7,392 KB
testcase_40 AC 41 ms
10,968 KB
testcase_41 AC 40 ms
11,024 KB
testcase_42 AC 38 ms
10,792 KB
testcase_43 AC 40 ms
10,908 KB
testcase_44 AC 593 ms
78,764 KB
testcase_45 AC 40 ms
11,060 KB
testcase_46 AC 40 ms
10,820 KB
testcase_47 AC 39 ms
10,720 KB
testcase_48 AC 68 ms
16,480 KB
testcase_49 AC 65 ms
15,792 KB
testcase_50 AC 68 ms
15,728 KB
testcase_51 AC 1 ms
4,384 KB
testcase_52 AC 84 ms
19,736 KB
testcase_53 AC 532 ms
70,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int ans[MAX_N];
int a[MAX_N];
int n;
int ok = 0;

map<int,vector<int>> mp;
vector<int> tmp;
int x;

void dfs(int i, int j){
    if(ok)return;
    if(i == n || j >= 22){
        return;
    }
    dfs(i+1,j);
    if(ok)return;
    int y = x + a[i];
    int xx = x;
    if(mp.find(y) != mp.end()){
        ok = 1;
        vector<int> keep = mp[y];
        tmp.push_back(i);

        rep(i,keep.size()){
            // cout << keep[i] << ' ';
            ans[keep[i]]++;
        }
        // cout << endl;

        rep(i,tmp.size()){
            // cout << tmp[i] << ' ';
            ans[tmp[i]]--;
        }
        // cout << endl;

        return;
    }else{
        x = y;
        tmp.push_back(i);
        mp[y] = tmp;
        dfs(i+1,j+1);
    }

    x = xx;
    tmp.erase(tmp.end()-1);

}

int main() {
    cin >> n;
    rep(i,n)cin >> a[i];

    dfs(0,0);

    if(ok == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        rep(i,n){
            cout << a[i] * ans[i];
            if(i == n - 1) cout << endl;
            else cout << " ";
        }
    }

    return 0;
}
 
 
0