結果

問題 No.265 数学のテスト
コンテスト
ユーザー bal4u
提出日時 2019-04-19 12:00:53
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,589 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 395 ms
コンパイル使用メモリ 40,392 KB
最終ジャッジ日時 2026-02-22 03:06:34
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder: No.265 数学のテスト
// 2019.4.19 bal4u

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s)
{
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
}

char S[50005]; int N;
int d;

char *factor(int *k, int *i, char *s)
{
	int t = 1, a, n = 0;
	while (*s) {
		if (*s == 'x') s++, n++;
		else if (isdigit(*s)) {
			a = 0; while (isdigit(*s)) {
				a = a * 10 + (*s++ & 0xf);
			}
			t *= a;
		} else if (*s == '*') s++;
		else break;
	}
	*k = t, *i = n;
	return s;
}

void parse(int *x, char *s)
{
	int i, k, y[11];
	char *p;

	memset(x, 0, sizeof(int)*(d+1));
	while (*s) {
		if (*s == 'd') {
			k = 1, s += 2, p = s++;
			while (*s) {
				if (*s == '{') k++;
				else if (*s == '}') {
					if (--k == 0) {
						*s++ = 0;
						parse(y, p);
						for (i = 1; i <= d; i++) {
							if (y[i] != 0) x[i-1] += y[i]*i;
						}
						break;
					}
				}
				s++;
			}
		} else if (*s == 'x' || isdigit(*s)) {
			s = factor(&k, &i, s);
			x[i] += k;
		} else if (*s == '+') s++;
	}
}

int main()
{
	int i, x[11];

	N = in(), d = in();
	ins(S);
	parse(x, S);
	out(x[0]); for (i = 1; i <= d; i++) pc(' '), out(x[i]);
	pc('\n');
	return 0;
}
0