結果
| 問題 |
No.1017 Reiwa Sequence
|
| ユーザー |
maspy
|
| 提出日時 | 2020-03-16 18:59:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,484 bytes |
| コンパイル時間 | 1,187 ms |
| コンパイル使用メモリ | 160,000 KB |
| 実行使用メモリ | 813,644 KB |
| 最終ジャッジ日時 | 2024-07-03 00:15:36 |
| 合計ジャッジ時間 | 8,749 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 MLE * 1 -- * 43 |
ソースコード
#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;
}
maspy