結果
問題 | No.238 Mr. K's Another Gift |
ユーザー |
![]() |
提出日時 | 2019-06-08 18:37:50 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,102 bytes |
コンパイル時間 | 296 ms |
コンパイル使用メモリ | 29,696 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-05 23:46:42 |
合計ジャッジ時間 | 1,634 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
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, d, *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)) c = *q, d = *p, *p = 0, outs(s), pc(c), pc(d), outs(p+1); else if (check(0, p, q, *p)) c = *p, d = *q, *q = 0, outs(s), pc(d), pc(c), outs(q+1); 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; }