結果
| 問題 | No.193 筒の数式 |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-13 11:29:23 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,019 bytes |
| 記録 | |
| コンパイル時間 | 410 ms |
| コンパイル使用メモリ | 30,592 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-15 07:20:58 |
| 合計ジャッジ時間 | 1,198 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
コンパイルメッセージ
main.c: In function 'ins':
main.c:10:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
10 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:19:17: note: in expansion of macro 'gc'
19 | do *s = gc();
| ^~
ソースコード
// 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;
}
bal4u