提交记录 31474


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 1000f. 测测你的实数 A+B Runtime Error 0 3.01 us 8 KB C++ 9.44 KB
提交时间 评测时间
2026-08-14 02:03:45 2026-08-14 02:03:47
// 1000f: 测测你的实数 A+B  --  fast I/O + skip libc startup + fast exit
// contestant.o is linked before tasklib.o, so defining symbols overrides musl's.
#include <stdint.h>
#include <stdarg.h>

// ---------------- power-of-ten tables ----------------
static const double POW10P[23] = {
    1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,
    1e12,1e13,1e14,1e15,1e16,1e17,1e18,1e19,1e20,1e21,1e22
};
static const double POW10N[23] = {
    1e0,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,
    1e-12,1e-13,1e-14,1e-15,1e-16,1e-17,1e-18,1e-19,1e-20,1e-21,1e-22
};
static const unsigned long long POW10I[19] = {
    1ULL,10ULL,100ULL,1000ULL,10000ULL,100000ULL,1000000ULL,10000000ULL,
    100000000ULL,1000000000ULL,10000000000ULL,100000000000ULL,
    1000000000000ULL,10000000000000ULL,100000000000000ULL,
    1000000000000000ULL,10000000000000000ULL,100000000000000000ULL,
    1000000000000000000ULL
};

// ---------------- duckinfo (JudgeDuck I/O memory) ----------------
static unsigned long* g_di = 0;
static const char* in_cursor;
static char* out_cursor;
static char* out_base;

static inline void putc_fast(char c) { *out_cursor++ = c; }

// ---------------- fast double parse ----------------
static double parse_double() {
    const char *p = in_cursor;
    while (*p==' '||*p=='\t'||*p=='\n'||*p=='\r'||*p=='\v'||*p=='\f') p++;
    int neg = 0;
    if (*p=='+') p++;
    else if (*p=='-') { neg=1; p++; }
    unsigned long long mant = 0;
    int exp10 = 0;
    int dot = 0;
    for (;;) {
        unsigned char c = (unsigned char)*p;
        if (c >= '0' && c <= '9') {
            if (mant < 1000000000000000000ULL) {
                mant = mant*10 + (unsigned)(c-'0');
                if (dot) exp10--;
            }
            p++;
        } else if (c=='.' && !dot) {
            dot = 1; p++;
        } else break;
    }
    if (*p=='e'||*p=='E') {
        p++;
        int es=1;
        if (*p=='+') p++;
        else if (*p=='-') { es=-1; p++; }
        int e=0;
        while (*p>='0'&&*p<='9') { e = e*10 + (*p-'0'); p++; }
        exp10 += es*e;
    }
    in_cursor = p;
    double v = (double)mant;
    if (exp10 > 0) {
        if (exp10 <= 22) v *= POW10P[exp10];
        else v *= POW10P[22];
    } else if (exp10 < 0) {
        int k = -exp10;
        if (k <= 22) v *= POW10N[k];
        else v *= POW10N[22];
    }
    return neg ? -v : v;
}

static long long parse_int() {
    const char *p = in_cursor;
    while (*p==' '||*p=='\t'||*p=='\n'||*p=='\r'||*p=='\v'||*p=='\f') p++;
    int neg = 0;
    if (*p=='+') p++;
    else if (*p=='-') { neg=1; p++; }
    unsigned long long v = 0;
    while (*p>='0'&&*p<='9') { v = v*10 + (unsigned)(*p-'0'); p++; }
    in_cursor = p;
    return neg ? -(long long)v : (long long)v;
}

// ---------------- fast double print ----------------
static void print_double(double x, int prec) {
    if (x < 0) { putc_fast('-'); x = -x; }
    if (prec < 0) prec = 6;
    if (prec > 9) prec = 9;
    unsigned long long scale = POW10I[prec];
    unsigned long long scaled = (unsigned long long)(x * POW10P[prec] + 0.5);
    unsigned long long whole = scaled / scale;
    unsigned long long frac = scaled % scale;
    char tmp[24];
    int n = 0;
    do { tmp[n++] = (char)('0' + (int)(whole % 10)); whole /= 10; } while (whole);
    while (n) putc_fast(tmp[--n]);
    if (prec > 0) {
        putc_fast('.');
        for (int i = 0; i < prec; i++) { tmp[i] = (char)('0' + (int)(frac % 10)); frac /= 10; }
        for (int i = prec-1; i >= 0; i--) putc_fast(tmp[i]);
    }
}

static void print_int(long long v) {
    unsigned long long u;
    if (v < 0) { putc_fast('-'); u = (unsigned long long)(-(v+1)) + 1ULL; }
    else u = (unsigned long long)v;
    char tmp[24];
    int n = 0;
    do { tmp[n++] = (char)('0' + (int)(u % 10)); u /= 10; } while (u);
    while (n) putc_fast(tmp[--n]);
}

// ---------------- printf family ----------------
static int vprintf_impl(const char *fmt, va_list ap) {
    const char *f = fmt;
    int count = 0;
    while (*f) {
        if (*f != '%') { putc_fast(*f++); count++; continue; }
        f++;
        while (*f=='-'||*f=='+'||*f==' '||*f=='#'||*f=='0') f++;
        while (*f>='0'&&*f<='9') f++;
        int prec = -1;
        if (*f=='.') { f++; prec=0; while (*f>='0'&&*f<='9'){ prec=prec*10+(*f-'0'); f++; } }
        int is_ll = 0;
        if (*f=='l') { f++; if (*f=='l'){ is_ll=1; f++; } }
        else if (*f=='h'||*f=='L'||*f=='j'||*f=='z'||*f=='t') f++;
        char c = *f++;
        if (c=='f'||c=='F'||c=='e'||c=='E'||c=='g'||c=='G') {
            double d = va_arg(ap, double);
            print_double(d, prec);
            count += 12;
        } else if (c=='d'||c=='i') {
            long long v = is_ll ? va_arg(ap, long long) : (long long)va_arg(ap, int);
            print_int(v);
            count += 8;
        } else if (c=='u'||c=='x'||c=='X'||c=='o') {
            unsigned long long v = is_ll ? va_arg(ap, unsigned long long) : (unsigned long long)va_arg(ap, unsigned int);
            print_int((long long)v);
            count += 8;
        } else if (c=='s') {
            const char *s = va_arg(ap, const char*);
            while (*s) { putc_fast(*s++); count++; }
        } else if (c=='c') {
            putc_fast((char)va_arg(ap, int)); count++;
        } else if (c=='p') {
            print_int((long long)(unsigned long)va_arg(ap, void*)); count += 8;
        } else if (c=='%') {
            putc_fast('%'); count++;
        }
    }
    g_di[5] = (unsigned long)(out_cursor - out_base);
    return count;
}

extern "C" int printf(const char *fmt, ...) {
    va_list ap; va_start(ap, fmt);
    int r = vprintf_impl(fmt, ap);
    va_end(ap); return r;
}
extern "C" int vprintf(const char *fmt, va_list ap) {
    return vprintf_impl(fmt, ap);
}
extern "C" int fprintf(void *f, const char *fmt, ...) {
    va_list ap; va_start(ap, fmt);
    int r = vprintf_impl(fmt, ap);
    va_end(ap); return r;
}
extern "C" int vfprintf(void *f, const char *fmt, va_list ap) {
    return vprintf_impl(fmt, ap);
}

// ---------------- scanf family ----------------
static int vscanf_impl(const char *fmt, va_list ap) {
    const char *f = fmt;
    int ret = 0;
    while (*f) {
        unsigned char fc = (unsigned char)*f;
        if (fc==' '||fc=='\t'||fc=='\n'||fc=='\r'||fc=='\v'||fc=='\f') {
            while (*in_cursor==' '||*in_cursor=='\t'||*in_cursor=='\n'||*in_cursor=='\r'||*in_cursor=='\v'||*in_cursor=='\f') in_cursor++;
            f++;
        } else if (fc != '%') {
            if (*in_cursor == fc) in_cursor++;
            f++;
        } else {
            f++;
            int is_l = 0, is_ll = 0, is_L = 0;
            if (*f=='l'){ is_l=1; f++; if(*f=='l'){ is_ll=1; f++; } }
            else if (*f=='L'){ is_L=1; f++; }
            else if (*f=='h'){ f++; }
            char c = *f++;
            if (c=='f'||c=='e'||c=='E'||c=='g'||c=='G') {
                double d = parse_double();
                if (is_L) { long double *pd = va_arg(ap, long double*); *pd = (long double)d; }
                else if (is_l || is_ll) { double *pd = va_arg(ap, double*); *pd = d; }
                else { float *pf = va_arg(ap, float*); *pf = (float)d; }
                ret++;
            } else if (c=='d'||c=='i') {
                long long v = parse_int();
                if (is_ll) *va_arg(ap, long long*) = v;
                else if (is_l) *va_arg(ap, long*) = (long)v;
                else *va_arg(ap, int*) = (int)v;
                ret++;
            } else if (c=='u'||c=='o'||c=='x'||c=='X') {
                long long v = parse_int();
                if (is_ll) *va_arg(ap, unsigned long long*) = (unsigned long long)v;
                else *va_arg(ap, unsigned*) = (unsigned)v;
                ret++;
            } else if (c=='%') {
                if (*in_cursor=='%') in_cursor++;
                else ret = -1;
            }
        }
    }
    return ret;
}

extern "C" int scanf(const char *fmt, ...) {
    va_list ap; va_start(ap, fmt);
    int r = vscanf_impl(fmt, ap);
    va_end(ap); return r;
}
extern "C" int vscanf(const char *fmt, va_list ap) {
    return vscanf_impl(fmt, ap);
}
extern "C" int fscanf(void *f, const char *fmt, ...) {
    va_list ap; va_start(ap, fmt);
    int r = vscanf_impl(fmt, ap);
    va_end(ap); return r;
}
extern "C" int vfscanf(void *f, const char *fmt, va_list ap) {
    return vscanf_impl(fmt, ap);
}

// ---------------- fast exit ----------------
static inline void duck_exit(int code) {
    __asm__ volatile("syscall" : : "a"(60), "D"(code) : "rcx", "r11", "memory");
    __builtin_unreachable();
}

extern "C" void exit(int code) { duck_exit(code); }
extern "C" void _exit(int code) { duck_exit(code); }
extern "C" void _Exit(int code) { duck_exit(code); }

// ---------------- skip libc startup ----------------
extern "C" void __libc_start_main(int (*main_fn)(int, char**, char**),
                                   int argc, char **argv,
                                   void (*init)(void), void (*fini)(void),
                                   void (*ldso)(void)) {
    // find auxv: argv[argc] == NULL, then envp until NULL, then auxv
    char **p = argv + argc + 1;
    while (*p) p++;
    p++;
    unsigned long *auxv = (unsigned long*)p;
    g_di = 0;
    while (auxv[0] != 0) {
        if (auxv[0] == 0x6b637564ULL) { g_di = (unsigned long*)auxv[1]; break; }
        auxv += 2;
    }
    in_cursor = (const char*)g_di[1];
    out_base = (char*)g_di[3];
    out_cursor = out_base;

    int r = main_fn(argc, argv, (char**)0);
    duck_exit(r);
}

// ---------------- the actual answer ----------------
double plus(double a, double b) {
    return a + b;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #13.01 us8 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-12 08:25:53 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠