結果

問題 No.265 数学のテスト
ユーザー kyuridenamidakyuridenamida
提出日時 2015-08-07 22:46:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,570 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 150,848 KB
実行使用メモリ 9,456 KB
最終ジャッジ日時 2023-08-16 01:58:40
合計ジャッジ時間 2,946 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,456 KB
testcase_01 AC 6 ms
6,696 KB
testcase_02 AC 8 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int d;
const double eps = 1e-9;
// 多項式 たとえば y=x^3 + -3x +5 なら y=[5,-3,0,1] みたいな表現
typedef vector<double> Poly;

// 無駄な係数0の高次項を消す
Poly normalize(Poly p){
	while( p.size() && p.back() == 0 ) p.pop_back();
	p.resize(d+1);
	return p;
}
//多項式の微分
Poly dfdx(Poly p){
	Poly res;
	if( p.size() != 0 ){
		res.resize(p.size()-1);
		for(int i = 0 ; i < res.size() ; i++)
			res[i] = (i+1) * p[i+1];
	}
	res.resize(d+1);
	return res;
}


string s;
int p;

Poly operator + (Poly a,Poly b){
	for(int i = 0 ; i < b.size() ; i++) a[i] += b[i];
	return a;
}
Poly operator * (Poly a,Poly b){
	Poly c(d+1);
	for(int i = 0 ; i < a.size() ; i++){
		for(int j = 0 ; j < b.size() ; j++){
			if( i + j < c.size() )
				c[i+j] += a[i]*b[j];		
		}
	}
	return c;
}

Poly f();
Poly g();
Poly h();

Poly f(){
	Poly r = g();
	
	while( s[p] == '+' ){
		p++;
		r = r + g();
	}
	return r;
}
Poly g(){
	Poly r = h();
	while( s[p] == '*' ){
		p++;
		Poly t = h();
		r = r * t;
	}
	return r;
}

Poly h(){
	if( s[p] == 'd' ){
		p += 2;
		Poly r = f();
		p++;
		return dfdx(r);
	}else{
		if( s[p] == 'x' ){
			Poly r(d+1);
			r[1] = 1;
			p++;
			return r;
		}else{
			double ans = 0;
			while( '0' <= s[p] && s[p] <= '9' ) 
				ans = ans * 10 + s[p++] - '0';
			Poly r = Poly(d+1);
			r[0] = ans;
			return r;
		}
	}
}
int main(){
	int N;
	
	cin >> N;
	cin >> d;
	cin >> s;
	p = 0;
	Poly r = f();
	for(int i = 0 ; i < r.size() ; i++)
		cout << (long long)r[i] << (i+1==r.size()?"\n":" ");
	
}
0