結果
問題 | No.428 小数から逃げる夢 |
ユーザー |
![]() |
提出日時 | 2019-04-17 18:01:41 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 1,916 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 31,360 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 08:36:41 |
合計ジャッジ時間 | 2,445 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
コンパイルメッセージ
main.c: In function 'in': main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 8 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:16:24: note: in expansion of macro 'gc' 16 | int n = 0, c = gc(); | ^~ main.c: In function 'outs': main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration] 9 | #define pc(c) putchar_unlocked(c) | ^~~~~~~~~~~~~~~~ main.c:21:33: note: in expansion of macro 'pc' 21 | void outs(char *s) { while (*s) pc(*s++); } | ^~
ソースコード
// yukicoder: No.428 小数から逃げる夢 // 2019.4.17 bal4u #include <stdio.h> #include <string.h> #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } void outs(char *s) { while (*s) pc(*s++); } #define N 1000000000 char *s = "1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991"; int num[30]; int ans[30]; char _ans[200]; void mpStr2Num(int *num, char *str, int len) { char *ss = str + len; int *nn = num, k = 1, x = 0; do { x += (*--ss - '0') * k; k *= 10; if (k == N || ss == str) *++nn = x, x = 0, k = 1; } while (ss != str); *num = nn - num; } void mpNum2Str(char *str, int *num) { int i, j, x; char *ss; if (*num == 0 || (*num == 1 && *(num + 1) == 0)) { *str++ = '0', *str = '\0'; return; } ss = str - 1; for (i = *num; i > 0; i--) { x = *++num; for (j = 1; j < N; j *= 10) { *++ss = x % 10 + '0'; x /= 10; } } while (*ss == '0') ss--; *(ss + 1) = '\0'; while (str < ss) { x = *str; *str++ = *ss; *ss-- = x; } } void mpMul(int *ret, int *a, int b) { int i, la, ca, *aa; long long x; la = *a; for (i = la + 1; i > 0; i--) *(ret + i) = 0; ca = 0; for (i = 1, aa = a; i <= la; i++) { x = *++aa; x = x * b + *(ret + i) + ca; *(ret + i) = x % N; ca = (int)(x / N); } *(ret + i) = ca; *ret = (ca != 0) ? la + 1 : la; } int main() { int n; n = in(); mpStr2Num(num, s, strlen(s)); mpMul(ans, num, n); mpNum2Str(_ans, ans); if (n <= 8) pc('0'), pc('.'), outs(_ans); else if (n <= 81) pc(_ans[0]), pc('.'), outs(_ans+1); else pc(_ans[0]), pc(_ans[1]), pc('.'), outs(_ans + 2); pc('\n'); return 0; }