結果

問題 No.40 多項式の割り算
ユーザー NotationNap
提出日時 2015-05-05 08:33:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 688 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 162,084 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 19:06:01
合計ジャッジ時間 2,254 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))

vector<int> remainder(vector<int> a, vector<int> b) {
	for (int i = 0; i + b.size() <= a.size(); i++) {
		int d = a[i] / b[0];
		for (int j = 0; j < b.size(); j++) {
			a[i + j] -= b[j] * d;
		}
	}
	while (a.size() >= 2 && a[0] == 0) a.erase(a.begin());
	return a;
}

int main() {
	int D; cin >> D;
	vector<int> a(D+1);
	REP(i, D+1) {
		cin >> a[D-i];
	}
	vector<int> b{1,0,-1,0};

	vector<int> r = remainder(a, b);

	reverse(r.begin(), r.end());
	cout << (r.size()-1) << endl;
	cout << r[0];
	for (int i = 1; i < r.size(); i++) cout << " " << r[i];
	cout << endl;
}
0