結果
| 問題 |
No.40 多項式の割り算
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-01-07 00:33:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,206 bytes |
| コンパイル時間 | 3,711 ms |
| コンパイル使用メモリ | 275,428 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-07 00:33:35 |
| 合計ジャッジ時間 | 4,109 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#else
#define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
// P(x) = (x - 1) Q1(x) + R1(x) => P( 1) = R1( 1)
// P(x) = (x + 1) Q2(x) + R2(x) => P(-1) = R2(-1)
// P(x) = x Q3(x) + R3(x) => P( 0) = R3( 0)
// P(x) = (x^3 - x) Q(x) + ax^2 + bx + c
// P(1) = a + b + c = R1(1)
// P(-1) = a - b + c = R2(-1)
// P(0) = c = R3(0)
// a = (R1(1) + R2(-1)) / 2 - c
// b = R1(1) - a - c
// c = R3(0)
int n;
cin >> n;
vector<int> d(n + 1);
rep(i, n + 1) cin >> d[i];
int p1 = 0, p2 = 0;
rep(i, n + 1) {
p1 += d[i];
p2 += d[i] * (i % 2 == 1 ? -1 : 1);
}
int c = d[0];
// p1 - p2 は a[i] * 0 or a[i] * 2 の差なので偶数になるはず
assert((p1 + p2) % 2 == 0);
int a = (p1 + p2) / 2 - c;
int b = p1 - a - c;
if (a == 0 && b == 0) {
cout << 0 << endl;
cout << c << endl;
}
else if (a == 0) {
cout << 1 << endl;
cout << c << ' ' << b << endl;
}
else {
cout << 2 << endl;
cout << c << ' ' << b << ' ' << a << endl;
}
return 0;
}
a01sa01to