結果
問題 | No.528 10^9と10^9+7と回文 |
ユーザー |
![]() |
提出日時 | 2019-06-28 09:37:30 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,551 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 31,616 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 04:01:35 |
合計ジャッジ時間 | 1,381 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 WA * 8 |
コンパイルメッセージ
main.c: In function 'ins': main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 9 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:18:21: note: in expansion of macro 'gc' 18 | while ((c = gc()) > ' ') w++, *s++ = c & 0xf; | ^~ 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:26:17: note: in expansion of macro 'pc' 26 | if (!n) pc('0'); | ^~
ソースコード
// yukicoder: No.528 10^9と10^9+7と回文// 2019.6.28 bal4u#include <stdio.h>typedef long long ll;#if 1#define gc() getchar_unlocked()#define pc(c) putchar_unlocked(c)#else#define gc() getchar()#define pc(c) putchar(c)#endifint ins(char *s) {int w = 0, c;while ((c = gc()) > ' ') w++, *s++ = c & 0xf;return w;}void out(int n) {int i;char ob[20];if (!n) pc('0');else {i = 0; while (n) ob[i++] = n%10 + '0', n/=10;while (i--) pc(ob[i]);}pc('\n');}#define M1 1000000000#define M2 1000000007char S[100005]; int w;int check(int i, int r) {while (i <= r) {if (S[i] < S[w-i-1]) {while (S[i] == 0) S[i--] = 9;S[i]--;return i;}i++;}return i;}int main(){int i, k, x, a1, a2, t1, t2;ll p1, p2;w = ins(S);if (w == 1) { out(S[0]), out(S[0]); return 0; }k = w >> 1;x = w; while ((i = check(w-k, x)) < x && i >= w-k) x = i;if (--w & 1) k--;if (S[0] == 0) a1 = a2 = 0;else {a1 = a2 = S[k] + (k > 0);i = k - 1, p1 = p2 = 10;while (i >= 0) {x = S[i] - (i == 0 && S[w]);a1 = (a1 + x * p1) % M1, a2 = (a2 + x * p2) % M2;p1 = p1 * 10 % M1, p2 = p2 * 10 % M2;i--;}}t1 = t2 = 9;for (i = 0; i < w; i++) {if (t1 == 0) break;a1 = (a1 + t1) % M1, a2 = (a2 + t2) % M2;if (++i >= w) break;a1 = (a1 + t1) % M1, a2 = (a2 + t2) % M2;t1 = t1 * 10LL % M1, t2 = t2 * 10LL % M2;}while (i < w) {a2 = (a2 + t2) % M2;if (++i >= w) break;a2 = (a2 + t2) % M2, t2 = t2 * 10LL % M2;i++;}out(a1), out(a2);return 0;}