結果

問題 No.265 数学のテスト
ユーザー wahr69wahr69
提出日時 2015-08-07 23:26:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 72,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 02:02:28
合計ジャッジ時間 1,973 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

using namespace std;

typedef unsigned long long ull;
unordered_map<ull, ull> m; // 答えでkey乗の係数の合計がvalue

void addAnswer(ull zyousu, ull inner, ull offset) {
	ull ansZyousu = zyousu - inner;
	if (ansZyousu < 0) {
		return;
	}
	ull keisu = 1;
	for (ull 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;

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