結果

問題 No.265 数学のテスト
ユーザー Lepton_sLepton_s
提出日時 2015-08-07 23:03:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 607 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 78,848 KB
実行使用メモリ 7,752 KB
最終ジャッジ日時 2023-08-16 02:00:06
合計ジャッジ時間 3,741 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;

int n, d;
string s;

void expr(int l, int r, vector<long>& a);
void term(int l, int r, vector<long>& a);

void expr(int l, int r, vector<long>& a){
	int p = 0;
	for(int i = l; i <= r; i++){
		if(i==r || (p==0 && s[i]=='+')){
			vector<long> a2(d+1, 0);
			term(l, i, a2);
			l = i+1;
			for(int j = 0; j <= d; j++) a[j] += a2[j];
		}
		if(i==r) return;
		if(s[i]=='{') p++;
		if(s[i]=='}') p--;
	}
}

void term(int l, int r, vector<long>& a){
	if(s[l]=='d'){
		vector<long> a2(d+1, 0);
		expr(l+2, r-1, a2);
		for(int k = 1; k <= d; k++)
				a2[k-1] = k*a2[k];
			a2[d] = 0;
		for(int j = 0; j <= d; j++) a[j] += a2[j];
		return;
	}
	int cnst = 1, deg = 0;
	for(int i = l; i < r; i+=2){
		if(s[i]=='x') deg++;
		else cnst = s[i]-'0';
	}
	a[deg] += cnst;
}

int main(){
	cin>>n>>d>>s;
	vector<long> a(d+1, 0);
	n = s.size();
	expr(0, n, a);
	for(int i = 0; i <= d; i++) printf("%ld%c",a[i],i==d?'\n':' ');
	return 0;
}
0