結果
| 問題 |
No.238 Mr. K's Another Gift
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-06-08 18:10:14 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,146 bytes |
| コンパイル時間 | 560 ms |
| コンパイル使用メモリ | 29,696 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-05 23:45:29 |
| 合計ジャッジ時間 | 4,020 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 13 |
コンパイルメッセージ
main.c: In function 'ins':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
7 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:17:17: note: in expansion of macro 'gc'
17 | do *s = gc();
| ^~
main.c: In function 'outs':
main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
8 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:23:33: note: in expansion of macro 'pc'
23 | void outs(char *s) { while (*s) pc(*s++); }
| ^~
ソースコード
// yukicoder: 238 Mr. K's Another Gift
// 2019.6.8 bal4u
#include <stdio.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;
}
void outs(char *s) { while (*s) pc(*s++); }
int check(char p, char *a, char *b, char q) {
if (p > 0) {
if (*b-- != p) return 0;
} else {
if (*a++ != q) return 0;
}
while (a < b && *a == *b) a++, b--;
return a >= b;
}
char s[100005];
int main()
{
int N;
char c, *p, *q;
N = ins(s);
if (N == 1) pc(*s), pc(*s);
else {
p = s, q = s + N - 1;
while (p < q && *p == *q) p++, q--;
if (p < q) {
if (check(*q, p, q, 0)) pc(*q), outs(p);
else if (check(0, p, q, *p)) outs(p), pc(*p);
else outs("NA");
} else {
if (N & 1) {
c = s[0];
p = s; while (*p == c) p++;
if (*p == 0) outs(s), pc(c);
else outs("NA");
} else {
c = s[N/2], s[N/2] = 0, outs(s);
pc(c), pc(c), outs(s+N/2+1);
}
}
}
pc('\n');
return 0;
}
bal4u