結果

問題 No.1017 Reiwa Sequence
ユーザー maspymaspy
提出日時 2020-03-16 18:20:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,969 bytes
コンパイル時間 2,483 ms
コンパイル使用メモリ 154,444 KB
実行使用メモリ 7,356 KB
最終ジャッジ日時 2023-09-15 22:58:15
合計ジャッジ時間 12,537 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;

const int MOD = 1e9 + 7;

int sum_l[60000];
int sum_r[60000];
int A[150001];
int B[150001];
unordered_map<int, int> memo;

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;
    }
}

pair<int, int> find_same_value(int lsize, int rsize)
{
    for (int i = 1; i < lsize; i++)
    {
        if (sum_l[i] == 0)
            return make_pair(i, 0);
    }
    for (int j = 1; j < lsize; j++)
    {
        if (sum_l[j] == 0)
            return make_pair(0, j);
    }
    for (int i = 1; i < lsize; i++)
    {
        memo[sum_l[i]] = i;
    }
    for (int j = 1; j < rsize; j++)
    {
        if (memo.find(sum_r[j]) != memo.end())
        {
            int i = memo[sum_r[j]];
            return make_pair(i, j);
        }
    }
    return make_pair(-1, -1);
};

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int M = min(N, 20);
    int mid = M / 2;
    calc_sums(sum_l, 0, mid);
    calc_sums(sum_r, mid, M);
    int i, j;
    auto p = find_same_value(pow(3, mid), pow(3, M - mid));
    i = p.first;
    j = p.second;
    int coef[3] = {0, 1, -1};
    if (i == -1)
    {
        cout << "No" << endl;
    }
    else
    {
        int n = 0;
        while (i)
        {
            B[n] = coef[i % 3] * A[n];
            n++;
            i /= 3;
        }
        n = mid;
        while (j)
        {
            B[n] = coef[j % 3] * A[n];
            n++;
            j /= 3;
        }
        cout << "Yes" << endl;
        for (int i = 0; i < N; i++)
        {
            if (i)
            {
                cout << " ";
            }
            cout << B[i];
        }
        cout << endl;
    }
    return 0;
}
0