結果

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

テストケース

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

ソースコード

diff #

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

using namespace std;

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] == '}') {
			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 (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