結果

問題 No.40 多項式の割り算
コンテスト
ユーザー tnakao0123
提出日時 2024-09-22 10:37:07
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 913 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 151 ms
コンパイル使用メモリ 53,876 KB
実行使用メモリ 16,768 KB
最終ジャッジ日時 2026-07-05 18:33:33
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- 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;
}
0