結果

問題 No.265 数学のテスト
ユーザー bal4ubal4u
提出日時 2019-04-19 12:25:56
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 30,896 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 17:25:49
合計ジャッジ時間 1,472 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:28: note: in expansion of macro 'gc'
   17 |         int n = 0; int c = gc();
      |                            ^~
main.c: In function 'out':
main.c:10:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:34:17: note: in expansion of macro 'pc'
   34 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// 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(long long n)
{
	int i;
	char ob[50];

	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(long long *k, int *i, char *s)
{
	int n = 0;
	long long t = 1, a;
	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(long long *x, char *s)
{
	int i;
	long long y[11];
	char *p;

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

int main()
{
	int i;
	long long 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