結果

問題 No.193 筒の数式
ユーザー bal4ubal4u
提出日時 2019-04-13 11:29:23
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,019 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 29,556 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 10:15:40
合計ジャッジ時間 2,137 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 0 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 0 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 0 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 0 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 0 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 0 ms
4,348 KB
testcase_16 AC 0 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘ins’ 内:
main.c:10:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:19:17: 備考: in expansion of macro ‘gc’
   19 |         do *s = gc();
      |                 ^~

ソースコード

diff #

// yukicoder: No.193 筒の数式
// 2019.4.13 bal4u

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

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

char S[30];

char *num(int *k, char *s)
{
	int n = 0;
	while (isdigit(*s)) n = 10 * n + (*s++ & 0xf);
	*k = n;
	return s;
}

int parse(char *s)
{
	int a, op, ans;
	
	s = num(&ans, s);
	while (*s) {
		op = *s++;
		s = num(&a, s);
		if (op == '+') ans += a;
		else ans -= a;
	}
	return ans;
}

int main()
{
	int i, c, w, a, ans;

	w = ins(S);
	memcpy(S + w, S, w);
	ans = -0x7fffffff;
	for (i = 0; i < w; i++) {
		if (isdigit(S[i]) && isdigit(S[i + w - 1])) {
			c = S[i + w], S[i + w] = 0;
			if ((a = parse(S + i)) > ans) ans = a;
			S[i + w] = c;
		}
	}
	printf("%d\n", ans);
	return 0;
}
0