結果
問題 | No.528 10^9と10^9+7と回文 |
ユーザー |
![]() |
提出日時 | 2019-06-28 10:14:30 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,673 bytes |
コンパイル時間 | 449 ms |
コンパイル使用メモリ | 32,000 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-23 18:35:38 |
合計ジャッジ時間 | 1,310 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
コンパイルメッセージ
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;void check(int l, int r) {int i = l, f = 0;while (i < r) {if (S[i] > S[w-i-1]) f = 1;else if (S[i] < S[w-i-1]) {if (f) return;i = l-1;while (S[i] == 0) S[i--] = 9;S[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;check(w-k, w);if (--w & 1) k--;// printf("w=%d, k=%d, --> ", w+1, k);// for (i = 0; i <= w; i++) printf("%d", S[i]); printf("\n");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);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;}