結果

問題 No.265 数学のテスト
ユーザー kyuridenamidakyuridenamida
提出日時 2015-08-07 22:44:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,280 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 159,652 KB
実行使用メモリ 9,432 KB
最終ジャッジ日時 2023-09-25 06:08:14
合計ジャッジ時間 5,189 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 2 ms
4,376 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 2 ms
4,380 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 AC 2 ms
4,380 KB
testcase_22 RE -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 RE -
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 RE -
testcase_29 WA -
testcase_30 RE -
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
4,376 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];
	}
	return res;
}
//多項式の割り算 res.first に商 res.second に余り
pair<Poly,Poly> pDiv(Poly f,Poly g){
	f = normalize(f);
	g = normalize(g);
	
	if( g.size() == 0 ) assert( "申し訳ないが0割りはNG" == "" );
	
	int m = max(f.size(),g.size());
	Poly p(m);
	while( f.size() >= g.size() ){
		int deg = f.size() - g.size();
		double coef = f.back() / g.back();
		p[deg] = coef;
		for(int i = 0 ; i < g.size() ; i++)
			f[i+deg] -= coef * g[i];
		f = normalize(f);
	}
	return {normalize(p),normalize(f)};
}

//多項式の計算
double calc(const Poly &p,double x){
	double ans = 0;
	for(int i = 0 ; i < p.size() ; i++)
		ans += p[i] * pow(x,i);
	return ans;
}

//多項式の表示(とりあえずできるだけ自然な表現になるようにしてる
void view(Poly p){
	p = normalize(p);
	if( p.size() == 0 ){
		cout << 0 << endl;
		return;
	}
	int fst = 0;
	for(int i = p.size()-1 ; i >= 0 ; i--){
		if( p[i] == 0 ) continue;
		if( fst++ && p[i] > 0 ) cout << "+";
		if( i != 0 && p[i] == 1 )cout << "";
		else if( i != 0 && p[i] == -1 )cout << "-";	
		else printf("%lf",p[i]);
		if( i >= 2 ) cout << "x^" << i;
		else if( i == 1 ) cout << "x";
	}
	cout << endl;
}

//すつるむ列を1つもってくる
vector<Poly> getSturm(Poly f){
	vector<Poly> fs(2);
	fs[0] = normalize(f);
	fs[1] = normalize(dfdx(f));	
	for(int i = 1 ; ; i++){
		if( fs[i].size() > 1){
			Poly remain = pDiv(fs[i-1],fs[i]).second;
			for( auto &x : remain ) x = -x;
			fs.push_back(normalize(remain));
		}else break;
	}
	if( fs.back().size() == 0 ){
		// 定数が0になっちゃうなら,多分重根の解となる式?を使って次数を下げる問題に帰着させる
		return getSturm(pDiv(f,fs[fs.size()-2]).first);
	}
	return fs;
}


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