結果
問題 | No.9001 標準入出力の練習問題(テスト用) |
ユーザー | scaler |
提出日時 | 2024-09-02 10:47:25 |
言語 | C (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,309 bytes |
コンパイル時間 | 491 ms |
コンパイル使用メモリ | 31,872 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-02 10:47:27 |
合計ジャッジ時間 | 1,395 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ソースコード
#include <assert.h>#include <inttypes.h>#include <stdint.h>#include <stdio.h>#include <string.h>#include <sys/mman.h>#include <sys/stat.h>#include <unistd.h>typedef uint32_t u32;typedef uint64_t u64;typedef __uint128_t u128;static char *input;static size_t input_size, input_string_size;__attribute__((constructor))void _construct_read_(void) {struct stat st;fstat(0, &st);input_string_size = st.st_size - 1;input_size = st.st_size + 1;input = (char *)mmap(0, input_size, PROT_READ, MAP_PRIVATE, 0, 0);if (input == MAP_FAILED) {__builtin_trap();}}void rd(u64 *x) {char c = *input;if (c < '!') {*input++;c = *input;}for (*x = *input++ & 15; (c = *input++) >= '0';) {*x = *x * 10 + (c & 15);}}void rdl(char *s) {while (*input != '\n' || *input != '\0') {*s++ = *input++;}}__attribute__((destructor))void _destruct_read_(void) {munmap(input, input_size);input_size = input_string_size = 0;}static char output[1048577];static char output_block_str[40001];static u128 power10[39];static size_t output_size;__attribute__((constructor))void _construct_write_(void) {output_size = 0;for (size_t i = 0; i < 10000; i++) {size_t j = 4, k = i;while (j--) {output_block_str[i * 4 + j] = k % 10 + '0';k /= 10;}}power10[0] = 1ull;for (size_t i = 1; i < 39; i++) {power10[i] = power10[i - 1] * 10;}}void wt(u64 x) {size_t digit = 0;if (x >= power10[10]) {if (x >= power10[19]) { digit = 20; }else if (x >= power10[18]) { digit = 19; }else if (x >= power10[17]) { digit = 18; }else if (x >= power10[16]) { digit = 17; }else if (x >= power10[15]) { digit = 16; }else if (x >= power10[14]) { digit = 15; }else if (x >= power10[13]) { digit = 14; }else if (x >= power10[12]) { digit = 13; }else if (x >= power10[11]) { digit = 12; }else { digit = 11; }}else {if (x >= power10[9]) { digit = 10; }else if (x >= power10[8]) { digit = 9; }else if (x >= power10[7]) { digit = 8; }else if (x >= power10[6]) { digit = 7; }else if (x >= power10[5]) { digit = 6; }else if (x >= power10[4]) { digit = 5; }else if (x >= power10[3]) { digit = 4; }else if (x >= power10[2]) { digit = 3; }else if (x >= power10[1]) { digit = 2; }else { digit = 1; }}size_t len = digit;while (len >= 4) {len -= 4;memcpy(output + output_size + len, output_block_str + (x % 10000), 4);x /= 10000;}memcpy(output + output_size, output_block_str + x * 4 + (4 - len), len);output_size += digit;}void wtc(char c) {output[output_size++] = c;}__attribute__((destructor))void _destruct_write_(void) {if (__builtin_expect(output_size == 1048576, 0)) {fwrite(output, 1, output_size, stdout);output_size = 0;}}int main(void) {u64 a, b;char *s;rd(&a);rd(&b);rdl(s);wt(a + b);wt(' ');while (*s != '\0') {wtc(*s++);}fwrite(output, 1, output_size, stdout);}