#include <stdint.h>
struct DuckInfo {
uint64_t abi_version;
const char *stdin_ptr;
uint64_t stdin_size;
char *stdout_ptr;
uint64_t stdout_limit;
uint64_t stdout_size;
char *stderr_ptr;
uint64_t stderr_limit;
uint64_t stderr_size;
const char *IB_ptr;
uint64_t IB_limit;
char *OB_ptr;
uint64_t OB_limit;
uint64_t tsc_frequency;
} __attribute__((packed));
int main(int argc, char** argv, char** envp) { return 0; }
static const char d100[] =
"00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899";
static inline int parse_num(const char **pp) {
const char *p = *pp;
int neg = 0;
if (*p == '-') { neg = 1; p++; }
int v = 0;
__asm__ __volatile__(
"xorl %%eax, %%eax\n\t"
"1:\n\t"
"movzbl (%[p]), %%r8d\n\t"
"subl $48, %%r8d\n\t"
"cmpl $9, %%r8d\n\t"
"ja 2f\n\t"
"leal (%%eax,%%eax,4), %%eax\n\t"
"leal (%%r8d,%%eax,2), %%eax\n\t"
"incq %[p]\n\t"
"jmp 1b\n\t"
"2:\n\t"
: [v] "=a" (v), [p] "+r" (p)
:
: "r8", "cc"
);
if (neg) v = -v;
*pp = p;
return v;
}
int __libc_start_main(
int (*mainp)(int,char**,char**), int argc, char** argv,
void (*init)(void), void (*fini)(void), void (*rtld_fini)(void))
{
(void)mainp;(void)init;(void)fini;(void)rtld_fini;
char **envp = argv + argc + 1;
while (*envp) envp++;
unsigned long *auxv = (unsigned long*)(envp + 1);
struct DuckInfo *d = 0;
for (; auxv[0] != 0; auxv += 2) {
if (auxv[0] == 0x6b637564) { d = (struct DuckInfo*)auxv[1]; break; }
}
const char *p = d->stdin_ptr;
int nn = parse_num(&p);
p++;
char *o = d->stdout_ptr;
for (int i = 0; i < nn; i++) {
int a = parse_num(&p);
p++;
int b = parse_num(&p);
p++;
int s = a + b;
if (s < 0) { *o++ = '-'; s = -s; }
char tmp[12]; int k = 0;
while (s >= 100) {
int r = s % 100; s /= 100;
tmp[k++] = d100[2*r+1];
tmp[k++] = d100[2*r];
}
if (s >= 10) { tmp[k++] = d100[2*s+1]; tmp[k++] = d100[2*s]; }
else { tmp[k++] = (char)('0'+s); }
while (k) *o++ = tmp[--k];
*o++ = '\n';
}
d->stdout_size = (uint64_t)(o - d->stdout_ptr);
__asm__ volatile("syscall" : : "a"(60), "D"(0) : "rcx", "r11", "memory");
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 6.83 us | 8 KB | Accepted | Score: 100 | 显示更多 |