結果

問題 No.1017 Reiwa Sequence
ユーザー maspymaspy
提出日時 2020-03-16 18:59:20
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,484 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 145,800 KB
実行使用メモリ 814,568 KB
最終ジャッジ日時 2023-09-15 22:55:32
合計ジャッジ時間 4,257 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,404 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;

const int MOD = 1e9 + 7;

int sum[400000000];
int A[150001];
int B[150001];

void calc_sums(int a[], int L, int R)
{
    int pow3 = 1;
    for (int i = L; i < R; i++)
    {
        int x = A[i];
        for (int j = 0; j < pow3; j++)
        {
            a[j + pow3] = a[j] + x;
            a[j + pow3 + pow3] = a[j] - x;
        }
        pow3 *= 3;
    }
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int M = min(N, 19);
    int pow3 = 1;
    for (int i = 1; i < M; i++)
    {
        int x = A[i];
        for (int j = 0; j < pow3; j++)
        {
            sum[j + pow3] = sum[j] + x;
            sum[j + pow3 + pow3] = sum[j] - x;
        }
        pow3 *= 3;
    }
    int found = -1;
    for (int j = 1; j < pow(3, M - 1); j++)
    {
        if ((sum[j] == 0) || (sum[j] == A[0]) || (sum[j] == -A[0]))
        {
            found = j;
            break;
        }
    }
    if (found == -1)
    {
        cout << "No" << endl;
        return 0;
    }
    int x = found;
    int n = 1;
    int coef[3] = {0, 1, -1};
    int S = 0;
    while (x)
    {
        B[n] = coef[x % 3] * A[n];
        S += B[n];
        x /= 3;
        n++;
    }
    B[0] = -S;
    cout << "Yes" << endl;
    for (int i = 0; i < N; i++)
    {
        if (i)
        {
            cout << " ";
        }
        cout << B[i];
    }
    cout << endl;
    return 0;
}
0