結果
問題 |
No.40 多項式の割り算
|
ユーザー |
![]() |
提出日時 | 2024-09-22 10:37:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 913 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 40,704 KB |
最終ジャッジ日時 | 2025-02-24 11:31:11 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d", &d); | ~~~~~^~~~~~~~~~ main.cpp:28:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | for (int i = 0; i <= d; i++) scanf("%d", as + i); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 40.cc: No.40 螟夐・シ上・蜑イ繧顔ョ・- yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_D = 10000; /* typedef */ /* global variables */ int as[MAX_D + 1]; /* subroutines */ /* main */ int main() { int d; scanf("%d", &d); for (int i = 0; i <= d; i++) scanf("%d", as + i); // (1) f(0)=b0 // (2) f(1)=b0+b1+b2 // (3) f(-1)=b0-b1+b2 // (2)+(3)=f(1)+f(-1)=2b0+2b2 -> b2=(f(1)+f(-1)/2-b0 // (2)-(3)=f(1)-f(-1)=2b1 -> b1=(f(1)-f(-1))/2 int f0 = as[0], f1 = 0, f2 = 0; for (int i = 0; i <= d; i++) { f1 += as[i]; f2 += (! (i & 1)) ? as[i] : -as[i]; } int b0 = f0; int b1 = (f1 - f2) / 2; int b2 = (f1 + f2) / 2 - b0; if (b2 != 0) printf("2\n%d %d %d\n", b0, b1 ,b2); else if (b1 != 0) printf("1\n%d %d\n", b0, b1); else printf("0\n%d\n", b0); return 0; }