結果

問題 No.265 数学のテスト
ユーザー wahr69wahr69
提出日時 2015-08-07 23:08:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,484 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 71,944 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 06:14:52
合計ジャッジ時間 2,031 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

// 階乗
static int fact(int x) {
	if (x == 0) {
		return 1;
	} else {
		return x * fact(x - 1);
	}
}

unordered_map<int, int> m; // 答えでkey乗の係数の合計がvalue

void addAnswer(int zyousu, int inner, int offset) {
	int ansZyousu = zyousu - inner;
	if (ansZyousu < 0) {
		return;
	}
	int keisu = 1;
	for (int i = 0; i < inner; ++i) {
		keisu *= zyousu - i;
	}
	if (offset != 0) {
		keisu *= offset;
	}
	m[ansZyousu] += keisu;
}

int main() {
	int N, d;
	string S;

	cin >> N >> d >> S;

	int inner = 0; // 微分の数
	int zyousu = 0; // xの数
	int offset = 0; // 定数
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'd') {
			++inner;
			++i;
		} else if (S[i] == '}') {
			// ここまで集計する
			addAnswer(zyousu, inner, offset);
			--inner;
			zyousu = 0;
			offset = 0;
		} else if (S[i] == 'x') {
			zyousu += 1;
		} else if (S[i] == '+') {
			// ここまで集計する
			addAnswer(zyousu, inner, offset);
			zyousu = 0;
			offset = 0;
		} else if (S[i] >= '1' && S[i] <= '9') {
			if (offset == 0) {
				offset = S[i] - '0';
			} else {
				offset *= S[i] - '0';
			}
		}
	}

	if (S[N - 1] != '}') {
		// ここまで集計する
		addAnswer(zyousu, inner, offset);
	}

	for (int i = 0; i < d + 1; ++i) {
		if (i != 0) {
			cout << " ";
		}
		if (m.find(i) != m.end()) {
			cout << m[i];
		} else {
			cout << "0";
		}
	}
	cout << endl;

	getchar();
	getchar();

}
0