結果

問題 No.265 数学のテスト
ユーザー masamasa
提出日時 2015-08-07 23:48:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,448 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 64,372 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-25 06:28:40
合計ジャッジ時間 4,274 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 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 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 WA -
testcase_30 RE -
testcase_31 WA -
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;
int n, d;
string s;

int getDegree(int idx) {
	if (s[idx] != 'x') {
		return 0;
	}

	int degree = 1;

	while(idx < n - 2) {
		if (s[idx + 1] == '*' && s[idx + 2] == 'x') {
			degree++;
			idx += 2;
		} else {
			break;
		}
	}

	return degree;
}

int main() {


	cin >> n >> d;
	cin >> s;
	s += "+";

	vector<int> coefficient(d + 1, 0);
	n = s.size();

	int depth = 0;
	int product = 1;
	int degree = 0;
	for (int i = 0; i < n; i++) {
// printf("i %d %c\n", i, s[i]);
		if (isdigit(s[i])) {
			product = s[i] - '0';
			if (s[i + 1] == '*') {
				i++;
				continue;
			}
		} else if (s[i] == 'd') {
			i++; // {
			depth++;
		} else if (s[i] == 'x') {
			int degree_now = getDegree(i);


			degree = degree_now - depth;
			if (degree >= 0) {
				for (int i = 0; i < depth; i++) {
					product *= degree_now - i;
				}
			} else {
				product *= 0;
			}
// printf("degrees %d %d %d\n", degree, degree_now, product);
			i += (degree_now - 1) * 2;
			continue;
		} else {
			// + }
			if (s[i] == '}') {
				depth--;
			}
			if (isdigit(s[i - 1]) || s[i - 1] == 'x') {
// printf("add %d %d\n", degree, product);
				coefficient[degree] += product;
				product = 1;
			}
		}
	}

	for (int i = 0; i <= d; i++) {
		cout << coefficient[i];
		if (i != d) {
			cout << " ";
		} else {
			cout << endl;
		}
	}

	return 0;
}
0