結果
| 問題 |
No.265 数学のテスト
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-19 12:06:24 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 391 ms / 2,000 ms |
| コード長 | 1,646 bytes |
| コンパイル時間 | 292 ms |
| コンパイル使用メモリ | 30,976 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 11:22:56 |
| 合計ジャッジ時間 | 2,293 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
コンパイルメッセージ
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');
| ^~
ソースコード
// 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 k, y[11];
char *p;
memset(x, 0, sizeof(long long)*(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;
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;
}
bal4u