結果

問題 No.1017 Reiwa Sequence
ユーザー hitoare1
提出日時 2020-04-03 22:26:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,908 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 181,964 KB
実行使用メモリ 818,292 KB
最終ジャッジ日時 2024-07-03 04:23:59
合計ジャッジ時間 19,487 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 MLE * 1 -- * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<bool> use(5000000, false);
    vector<pair<vector<int>, int>> make;
    make.push_back({{}, 0});
    for (int i = 0; i < N; i++) {
        vector<pair<vector<int>, int>> nxt;
        for (auto p : make) {
            int sum = p.second, nsum;
            vector<int> c = p.first, nc;
            nc = c;
            nc.push_back(0);
            nxt.push_back({nc, sum});
            
            if (sum+A[i] == 0) {
                cout << "Yes\n";
                for (int j = 0; j < N; j++) {
                    if (j < i) cout << c[j]*A[j];
                    else if (j == i) cout << A[j];
                    else cout << 0;
                    if (j < N-1) cout << " ";
                }
                cout << endl;
                return 0;
            }
            
            if (sum-A[i] == 0) {
                cout << "Yes\n";
                for (int j = 0; j < N; j++) {
                    if (j < i) cout << c[j]*A[j];
                    else if (j == i) cout << -A[j];
                    else cout << 0;
                    if (j < N-1) cout << " ";
                }
                cout << endl;
                return 0;
            }
            
            
            if (!use[sum+A[i]+2500000]) {
                nsum = sum+A[i];
                nc = c;
                nc.push_back(1);
                nxt.push_back({nc, nsum});
                use[nsum+2500000] = true;
            }
            if (!use[sum-A[i]+2500000]) {
                nsum = sum-A[i];
                nc = c;
                nc.push_back(-1);
                nxt.push_back({nc, nsum});
                use[nsum+2500000] = true;
            }
        }
        make = nxt;
    }
    cout << "No\n";
    return 0;
}
0