結果

問題 No.40 多項式の割り算
ユーザー furafura
提出日時 2020-04-13 19:03:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 154 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 195,988 KB
最終ジャッジ日時 2025-01-09 18:10:48
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         int d; scanf("%d",&d);
      |                ~~~~~^~~~~~~~~
main.cpp:21:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         rep(i,d+1) scanf("%d",&a[i]);
      |                    ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

vector<int> solve(vector<int> a){
	if(a.empty()) return a;
	if(a.back()==0) return solve(vector<int>(a.begin(),--a.end()));
	int d=a.size()-1;
	if(d<=2) return a;

	vector<int> b(d+1);
	rep(i,d+1) b[i/3+i%3]+=a[i];
	return solve(b);
}

int main(){
	int d; scanf("%d",&d);
	vector<int> a(d+1);
	rep(i,d+1) scanf("%d",&a[i]);

	a=solve(a);
	if(a.empty()){
		puts("0\n0");
	}
	else{
		printf("%lu\n",a.size()-1);
		rep(i,a.size()) printf("%d%c",a[i],i<a.size()-1?' ':'\n');
	}

	return 0;
}
0