提交记录 61865


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 1002i. 【模板题】多项式乘法 Accepted 100 4.862 ms 6340 KB C++17 18.31 KB
提交时间 评测时间
2026-09-19 23:23:01 2026-09-19 23:23:06
// 1002: four-step (cache-blocked) NTT mod 998244353, Montgomery arithmetic, AVX2.
// n = m = 1e6; coefficients < 10 so result coefficients (< 8.1e7) are exact in Z_p.
//
// Pipeline (N = N1*N2):
//   L   : natural x[n1*N2+n2] -> T1[n2*N1+n1]   (tiled transpose + Montgomery convert)
//   D1  : DIF_N1 on every row of T1             (natural in, digit-reversed out)
//   P   : T1[n2][p] -> T2[PERM[p]][n2]          (tiled transpose; row permutation is free)
//   W   : T2[k1][n2] *= w_N^{k1*n2}             (per-row geometric progression)
//   D2  : DIF_N2 on every row of T2
// spectrum: T2[k1*N2+p] = X[k1 + N1*perm2(p)]
// inverse: DIT_N2 -> untwiddle -> P^-1 -> DIT_N1 -> store natural (with 1/N scale).
#include <immintrin.h>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <cstdlib>

typedef uint32_t u32;
typedef uint64_t u64;

static const u32 P = 998244353u;
static const u32 RMOD = 301989884u;      // 2^32 mod P  = mont(1)
static const u32 P1M = P - RMOD;         // mont(-1)
static const u32 R2MOD = 932051910u;     // 2^64 mod P
static const u32 NPM = 998244351u;       // -P^{-1} mod 2^32
static const u32 IVAL = 911660635u;      // g^((P-1)/4)  (plain)
static const u32 IVM = 691295370u;       // mont(I)
static const u32 IIVM = 306948983u;      // mont(-I)

#define AVX2 __attribute__((target("avx2")))

static inline u32 addm(u32 a, u32 b) { u32 s = a + b; return s >= P ? s - P : s; }
static inline u32 subm(u32 a, u32 b) { return a >= b ? a - b : a + P - b; }
static inline u32 mmul1(u32 a, u32 b) {
    u64 t = (u64)a * b;
    u32 m = (u32)((u32)t * NPM);
    u32 r = (u32)((t + (u64)m * P) >> 32);
    return r >= P ? r - P : r;
}
static u32 fpow(u32 a, u64 e) { u64 r = 1, b = a; while (e) { if (e & 1) r = r * b % P; b = b * b % P; e >>= 1; } return (u32)r; }

AVX2 static inline __m256i vaddp(__m256i a, __m256i b) {
    const __m256i pv = _mm256_set1_epi32((int)P);
    __m256i s = _mm256_add_epi32(a, b);
    return _mm256_min_epu32(s, _mm256_sub_epi32(s, pv));
}
AVX2 static inline __m256i vsubp(__m256i a, __m256i b) {
    const __m256i pv = _mm256_set1_epi32((int)P);
    __m256i d = _mm256_sub_epi32(a, b);
    return _mm256_min_epu32(d, _mm256_add_epi32(d, pv));
}
AVX2 static inline __m256i vmul(__m256i a, __m256i b) {
    const __m256i np = _mm256_set1_epi32((int)NPM);
    const __m256i pv = _mm256_set1_epi32((int)P);
    __m256i lo = _mm256_mul_epu32(a, b);
    __m256i hi = _mm256_mul_epu32(_mm256_srli_epi64(a, 32), _mm256_srli_epi64(b, 32));
    __m256i ml = _mm256_mul_epu32(lo, np);
    __m256i mh = _mm256_mul_epu32(hi, np);
    __m256i sl = _mm256_add_epi64(lo, _mm256_mul_epu32(ml, pv));
    __m256i sh = _mm256_add_epi64(hi, _mm256_mul_epu32(mh, pv));
    __m256i r = _mm256_blend_epi32(_mm256_srli_epi64(sl, 32), sh, 0xAA);
    return _mm256_min_epu32(r, _mm256_sub_epi32(r, pv));
}
AVX2 static inline __m256i vload(const u32 *p) { return _mm256_loadu_si256((const __m256i *)p); }
AVX2 static inline void vstore(u32 *p, __m256i v) { _mm256_storeu_si256((__m256i *)p, v); }

AVX2 static inline void tr8x8(__m256i *r) {
    __m256i t0 = _mm256_unpacklo_epi32(r[0], r[1]), t1 = _mm256_unpackhi_epi32(r[0], r[1]);
    __m256i t2 = _mm256_unpacklo_epi32(r[2], r[3]), t3 = _mm256_unpackhi_epi32(r[2], r[3]);
    __m256i t4 = _mm256_unpacklo_epi32(r[4], r[5]), t5 = _mm256_unpackhi_epi32(r[4], r[5]);
    __m256i t6 = _mm256_unpacklo_epi32(r[6], r[7]), t7 = _mm256_unpackhi_epi32(r[6], r[7]);
    __m256i u0 = _mm256_unpacklo_epi64(t0, t2), u1 = _mm256_unpackhi_epi64(t0, t2);
    __m256i u2 = _mm256_unpacklo_epi64(t1, t3), u3 = _mm256_unpackhi_epi64(t1, t3);
    __m256i u4 = _mm256_unpacklo_epi64(t4, t6), u5 = _mm256_unpackhi_epi64(t4, t6);
    __m256i u6 = _mm256_unpacklo_epi64(t5, t7), u7 = _mm256_unpackhi_epi64(t5, t7);
    r[0] = _mm256_permute2x128_si256(u0, u4, 0x20);
    r[1] = _mm256_permute2x128_si256(u1, u5, 0x20);
    r[2] = _mm256_permute2x128_si256(u2, u6, 0x20);
    r[3] = _mm256_permute2x128_si256(u3, u7, 0x20);
    r[4] = _mm256_permute2x128_si256(u0, u4, 0x31);
    r[5] = _mm256_permute2x128_si256(u1, u5, 0x31);
    r[6] = _mm256_permute2x128_si256(u2, u6, 0x31);
    r[7] = _mm256_permute2x128_si256(u3, u7, 0x31);
}

// ---- scalar reference row transforms (small sizes / fallback) ----
static void dif4s(u32 *a, int n, int M, const u32 *T1, const u32 *T2, const u32 *T3) {
    int L = M << 2;
    for (int base = 0; base < n; base += L) {
        u32 *p = a + base;
        for (int j = 0; j < M; j++) {
            u32 x0 = p[j], x1 = p[j + M], x2 = p[j + 2 * M], x3 = p[j + 3 * M];
            u32 t0 = addm(x0, x2), t1 = subm(x0, x2), t2 = addm(x1, x3), t3 = mmul1(subm(x1, x3), IVM);
            p[j] = addm(t0, t2);
            p[j + M] = mmul1(addm(t1, t3), T1[j]);
            p[j + 2 * M] = mmul1(subm(t0, t2), T2[j]);
            p[j + 3 * M] = mmul1(subm(t1, t3), T3[j]);
        }
    }
}
static void dit4s(u32 *a, int n, int M, const u32 *T1, const u32 *T2, const u32 *T3) {
    int L = M << 2;
    for (int base = 0; base < n; base += L) {
        u32 *p = a + base;
        for (int j = 0; j < M; j++) {
            u32 c0 = p[j], c1 = mmul1(p[j + M], T1[j]), c2 = mmul1(p[j + 2 * M], T2[j]), c3 = mmul1(p[j + 3 * M], T3[j]);
            u32 t0 = addm(c0, c2), t1 = subm(c0, c2), t2 = addm(c1, c3), t3 = mmul1(subm(c1, c3), IIVM);
            p[j] = addm(t0, t2);
            p[j + M] = addm(t1, t3);
            p[j + 2 * M] = subm(t0, t2);
            p[j + 3 * M] = subm(t1, t3);
        }
    }
}
AVX2 static void dif4v(u32 *a, int n, int M, const u32 *T1, const u32 *T2, const u32 *T3) {
    const __m256i iv = _mm256_set1_epi32((int)IVM);
    const int L = M << 2;
    for (int base = 0; base < n; base += L) {
        u32 *p = a + base;
        int j = 0;
        for (; j + 16 <= M; j += 16) {
            __m256i A0 = vload(p + j), A1 = vload(p + j + M), A2 = vload(p + j + 2 * M), A3 = vload(p + j + 3 * M);
            __m256i B0 = vload(p + j + 8), B1 = vload(p + j + M + 8), B2 = vload(p + j + 2 * M + 8), B3 = vload(p + j + 3 * M + 8);
            __m256i ta0 = vaddp(A0, A2), ta1 = vsubp(A0, A2), ta2 = vaddp(A1, A3), ta3 = vmul(vsubp(A1, A3), iv);
            __m256i tb0 = vaddp(B0, B2), tb1 = vsubp(B0, B2), tb2 = vaddp(B1, B3), tb3 = vmul(vsubp(B1, B3), iv);
            __m256i oa1 = vaddp(ta1, ta3), oa3 = vsubp(ta1, ta3), ob1 = vaddp(tb1, tb3), ob3 = vsubp(tb1, tb3);
            __m256i oa0 = vaddp(ta0, ta2), oa2 = vsubp(ta0, ta2), ob0 = vaddp(tb0, tb2), ob2 = vsubp(tb0, tb2);
            vstore(p + j, oa0);
            vstore(p + j + 8, ob0);
            vstore(p + j + M, vmul(oa1, vload(T1 + j)));
            vstore(p + j + M + 8, vmul(ob1, vload(T1 + j + 8)));
            vstore(p + j + 2 * M, vmul(oa2, vload(T2 + j)));
            vstore(p + j + 2 * M + 8, vmul(ob2, vload(T2 + j + 8)));
            vstore(p + j + 3 * M, vmul(oa3, vload(T3 + j)));
            vstore(p + j + 3 * M + 8, vmul(ob3, vload(T3 + j + 8)));
        }
        for (; j < M; j += 8) {
            __m256i x0 = vload(p + j), x1 = vload(p + j + M), x2 = vload(p + j + 2 * M), x3 = vload(p + j + 3 * M);
            __m256i t0 = vaddp(x0, x2), t1 = vsubp(x0, x2), t2 = vaddp(x1, x3), t3 = vmul(vsubp(x1, x3), iv);
            vstore(p + j, vaddp(t0, t2));
            vstore(p + j + M, vmul(vaddp(t1, t3), vload(T1 + j)));
            vstore(p + j + 2 * M, vmul(vsubp(t0, t2), vload(T2 + j)));
            vstore(p + j + 3 * M, vmul(vsubp(t1, t3), vload(T3 + j)));
        }
    }
}
AVX2 static void dit4v(u32 *a, int n, int M, const u32 *T1, const u32 *T2, const u32 *T3) {
    const __m256i iv = _mm256_set1_epi32((int)IIVM);
    const int L = M << 2;
    for (int base = 0; base < n; base += L) {
        u32 *p = a + base;
        int j = 0;
        for (; j + 16 <= M; j += 16) {
            __m256i c0 = vload(p + j), d0 = vload(p + j + 8);
            __m256i c1 = vmul(vload(p + j + M), vload(T1 + j));
            __m256i d1 = vmul(vload(p + j + M + 8), vload(T1 + j + 8));
            __m256i c2 = vmul(vload(p + j + 2 * M), vload(T2 + j));
            __m256i d2 = vmul(vload(p + j + 2 * M + 8), vload(T2 + j + 8));
            __m256i c3 = vmul(vload(p + j + 3 * M), vload(T3 + j));
            __m256i d3 = vmul(vload(p + j + 3 * M + 8), vload(T3 + j + 8));
            __m256i ta0 = vaddp(c0, c2), ta1 = vsubp(c0, c2), ta2 = vaddp(c1, c3), ta3 = vmul(vsubp(c1, c3), iv);
            __m256i tb0 = vaddp(d0, d2), tb1 = vsubp(d0, d2), tb2 = vaddp(d1, d3), tb3 = vmul(vsubp(d1, d3), iv);
            vstore(p + j, vaddp(ta0, ta2));
            vstore(p + j + 8, vaddp(tb0, tb2));
            vstore(p + j + M, vaddp(ta1, ta3));
            vstore(p + j + M + 8, vaddp(tb1, tb3));
            vstore(p + j + 2 * M, vsubp(ta0, ta2));
            vstore(p + j + 2 * M + 8, vsubp(tb0, tb2));
            vstore(p + j + 3 * M, vsubp(ta1, ta3));
            vstore(p + j + 3 * M + 8, vsubp(tb1, tb3));
        }
        for (; j < M; j += 8) {
            __m256i c0 = vload(p + j);
            __m256i c1 = vmul(vload(p + j + M), vload(T1 + j));
            __m256i c2 = vmul(vload(p + j + 2 * M), vload(T2 + j));
            __m256i c3 = vmul(vload(p + j + 3 * M), vload(T3 + j));
            __m256i t0 = vaddp(c0, c2), t1 = vsubp(c0, c2), t2 = vaddp(c1, c3), t3 = vmul(vsubp(c1, c3), iv);
            vstore(p + j, vaddp(t0, t2));
            vstore(p + j + M, vaddp(t1, t3));
            vstore(p + j + 2 * M, vsubp(t0, t2));
            vstore(p + j + 3 * M, vsubp(t1, t3));
        }
    }
}
AVX2 static void stage2(u32 *a, int n) {
    for (int i = 0; i < n; i += 8) {
        __m256i v = vload(a + i);
        __m256i t = _mm256_shuffle_epi32(v, 0xB1);
        __m256i s = vaddp(v, t);
        __m256i d = vsubp(t, v);
        vstore(a + i, _mm256_blend_epi32(s, d, 0xAA));
    }
}
// L=8 radix-4 stage (M=2): 8 blocks (64 elements) per iteration via 8x8 transposes
AVX2 static void tail8(u32 *a, int n, const u32 *T1, const u32 *T2, const u32 *T3, int dir) {
    const __m256i iv = _mm256_set1_epi32((int)(dir ? IIVM : IVM));
    const __m256i t1 = _mm256_set1_epi32((int)T1[1]), t2 = _mm256_set1_epi32((int)T2[1]), t3 = _mm256_set1_epi32((int)T3[1]);
    for (int g = 0; g < n; g += 64) {
        __m256i r[8];
        for (int i = 0; i < 8; i++) r[i] = vload(a + g + 8 * i);
        tr8x8(r);                                    // r[j] = position j across the 8 blocks
        for (int j = 0; j < 2; j++) {
            __m256i x0 = r[j], x1 = r[j + 2], x2 = r[j + 4], x3 = r[j + 6];
            if (dir && j) { x1 = vmul(x1, t1); x2 = vmul(x2, t2); x3 = vmul(x3, t3); }
            __m256i a0 = vaddp(x0, x2), a1 = vsubp(x0, x2), a2 = vaddp(x1, x3), a3 = vmul(vsubp(x1, x3), iv);
            __m256i b0 = vaddp(a0, a2), b1 = vaddp(a1, a3), b2 = vsubp(a0, a2), b3 = vsubp(a1, a3);
            if (!dir && j) { b1 = vmul(b1, t1); b2 = vmul(b2, t2); b3 = vmul(b3, t3); }
            r[j] = b0; r[j + 2] = b1; r[j + 4] = b2; r[j + 6] = b3;
        }
        tr8x8(r);
        for (int i = 0; i < 8; i++) vstore(a + g + 8 * i, r[i]);
    }
}
// L=16 radix-4 stage (M=4): 2 blocks (32 elements) per iteration
AVX2 static void tail16(u32 *a, int n, const u32 *T1, const u32 *T2, const u32 *T3, int dir) {
    const __m256i iv = _mm256_set1_epi32((int)(dir ? IIVM : IVM));
    const __m256i t1 = _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i *)T1));
    const __m256i t2 = _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i *)T2));
    const __m256i t3 = _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i *)T3));
    for (int base = 0; base < n; base += 32) {
        __m256i A = vload(a + base), B = vload(a + base + 8), C = vload(a + base + 16), D = vload(a + base + 24);
        __m256i x0 = _mm256_permute2x128_si256(A, C, 0x20);
        __m256i x1 = _mm256_permute2x128_si256(A, C, 0x31);
        __m256i x2 = _mm256_permute2x128_si256(B, D, 0x20);
        __m256i x3 = _mm256_permute2x128_si256(B, D, 0x31);
        if (dir) { x1 = vmul(x1, t1); x2 = vmul(x2, t2); x3 = vmul(x3, t3); }
        __m256i r0 = vaddp(x0, x2), r1 = vsubp(x0, x2), r2 = vaddp(x1, x3), r3 = vmul(vsubp(x1, x3), iv);
        __m256i b0 = vaddp(r0, r2), b1 = vaddp(r1, r3), b2 = vsubp(r0, r2), b3 = vsubp(r1, r3);
        if (!dir) { b1 = vmul(b1, t1); b2 = vmul(b2, t2); b3 = vmul(b3, t3); }
        vstore(a + base, _mm256_permute2x128_si256(b0, b1, 0x20));
        vstore(a + base + 8, _mm256_permute2x128_si256(b2, b3, 0x20));
        vstore(a + base + 16, _mm256_permute2x128_si256(b0, b1, 0x31));
        vstore(a + base + 24, _mm256_permute2x128_si256(b2, b3, 0x31));
    }
}
// L=4 radix-4 stage (M=1, no twiddles): 2 groups (8 elements) per iteration
AVX2 static void tail4(u32 *a, int n, int dir) {
    const __m256i K = _mm256_setr_epi32((int)RMOD, (int)(dir ? IIVM : IVM), (int)P1M, (int)(dir ? IVM : IIVM),
                                        (int)RMOD, (int)(dir ? IIVM : IVM), (int)P1M, (int)(dir ? IVM : IIVM));
    for (int i = 0; i < n; i += 8) {
        __m256i v = vload(a + i);
        __m256i w = _mm256_shuffle_epi32(v, 0x4E);
        __m256i s = vaddp(v, w);
        __m256i d = vsubp(v, w);
        __m256i E = _mm256_unpacklo_epi32(s, d);
        __m256i G = _mm256_shuffle_epi32(E, 0xD8);
        vstore(a + i, vaddp(_mm256_shuffle_epi32(G, 0x88), vmul(_mm256_shuffle_epi32(G, 0xDD), K)));
    }
}


// ---- tables: plain radix-4 NTT of size 2^18 ----
static const int NN = 1 << 18;
struct StageTab { int M; u32 *w1, *w2, *w3; };
static StageTab FW[10], IV[10];
static u32 poolF[270000], poolI[270000];

AVX2 static void buildStage(StageTab &t, int M, u32 wl, u32 *&pp) {
    u32 *t1 = pp, *t2 = pp + M, *t3 = pp + 2 * M; pp += 3 * M;
    t.M = M; t.w1 = t1; t.w2 = t2; t.w3 = t3;
    if (M < 8) {
        u32 cur = RMOD;                      // mont(1); wl is mont(w_L)
        for (int j = 0; j < M; j++) {
            t1[j] = cur;
            u32 v2 = mmul1(cur, cur);
            t2[j] = v2;
            t3[j] = mmul1(v2, cur);
            cur = mmul1(cur, wl);
        }
        return;
    }
    u32 base[8] __attribute__((aligned(32)));
    base[0] = RMOD;
    for (int i = 1; i < 8; i++) base[i] = mmul1(base[i - 1], wl);
    u32 wl8 = mmul1(base[7], wl);
    __m256i v = vload(base);
    const __m256i step = _mm256_set1_epi32((int)wl8);
    for (int j = 0; j < M; j += 8) { vstore(t1 + j, v); v = vmul(v, step); }
    for (int j = 0; j < M; j += 8) {
        __m256i a1 = vload(t1 + j), a2 = vmul(a1, a1);
        vstore(t2 + j, a2);
        vstore(t3 + j, vmul(a2, a1));
    }
}
AVX2 static void buildTables(void) {
    u32 *p = poolF, *q = poolI;
    int L = NN;
    for (int s = 0; s < 9; s++, L >>= 2) {
        u32 w = fpow(3, (P - 1) / L);
        buildStage(FW[s], L >> 2, (u32)((u64)w * RMOD % P), p);
        u32 wi = fpow(w, P - 2);
        buildStage(IV[s], L >> 2, (u32)((u64)wi * RMOD % P), q);
    }
}
AVX2 static void nttFwd(u32 *a) {
    for (int s = 0; s < 9; s++) {
        int M = FW[s].M;
        if (M >= 8) dif4v(a, NN, M, FW[s].w1, FW[s].w2, FW[s].w3);
        else if (M == 4) tail16(a, NN, FW[s].w1, FW[s].w2, FW[s].w3, 0);
        else tail4(a, NN, 0);
    }
}
AVX2 static void pointwise(u32 *a, const u32 *b) {
    for (int i = 0; i < NN; i += 8) vstore(a + i, vmul(vload(a + i), vload(b + i)));
}
AVX2 static void scaleAll(u32 *a, u32 sc) {
    const __m256i s = _mm256_set1_epi32((int)sc);
    for (int i = 0; i < NN; i += 8) vstore(a + i, vmul(vload(a + i), s));
}
AVX2 static void nttInv(u32 *a) {
    for (int s = 8; s >= 0; s--) {
        int M = IV[s].M;
        if (M >= 8) dit4v(a, NN, M, IV[s].w1, IV[s].w2, IV[s].w3);
        else if (M == 4) tail16(a, NN, IV[s].w1, IV[s].w2, IV[s].w3, 1);
        else tail4(a, NN, 1);
    }
}

// ---- I/O ----
static u32 bufA[NN + 8] __attribute__((aligned(32)));
static u32 bufB[NN + 8] __attribute__((aligned(32)));
static char inbuf[1 << 22];
static char outbuf[1 << 18];
static char DIG4[40000];
static const char DIG2S[401] =
    "00010203040506070809101112131415161718192021222324252627282930313233343536373839"
    "40414243444546474849505152535455565758596061626364656667686970717273747576777879"
    "8081828384858687888990919293949596979899";

int main(void) {
    size_t got = fread(inbuf, 1, sizeof(inbuf) - 1, stdin);
    inbuf[got] = 0;
    const char *p = inbuf;
    while (*p && (*p < '0' || *p > '9')) p++;
    int n = 0, m = 0;
    while (*p >= '0' && *p <= '9') n = n * 10 + (*p++ - '0');
    while (*p && (*p < '0' || *p > '9')) p++;
    while (*p >= '0' && *p <= '9') m = m * 10 + (*p++ - '0');
    for (int i = 0; i < 10000; i++) { int x = i; DIG4[4*i+3] = (char)('0' + x % 10); x /= 10; DIG4[4*i+2] = (char)('0' + x % 10); x /= 10; DIG4[4*i+1] = (char)('0' + x % 10); x /= 10; DIG4[4*i] = (char)('0' + x); }
    static u32 md[10];
    for (int i = 0; i < 10; i++) md[i] = (u32)((u64)i * RMOD % P);
    int la = n + 1, lb = m + 1;
    buildTables();
    for (int i = 0; i < la; i++) { while (*p < '0' || *p > '9') p++; bufA[i] = md[*p++ - '0']; }
    for (int i = la; i < NN; i++) bufA[i] = 0;
    for (int i = 0; i < lb; i++) { while (*p < '0' || *p > '9') p++; bufB[i] = md[*p++ - '0']; }
    for (int i = lb; i < NN; i++) bufB[i] = 0;
    nttFwd(bufA);
    nttFwd(bufB);
    pointwise(bufA, bufB);
    nttInv(bufA);
    u32 invN = fpow(NN, P - 2);
    scaleAll(bufA, invN);
    int lc = la + lb - 1;
    char *o = outbuf;
    const char *oend = outbuf + sizeof(outbuf) - 16;
    for (int i = 0; i < lc; i++) {
        u32 v = bufA[i];
        if (v < 10000) {
            if (v < 10) *o++ = (char)('0' + v);
            else if (v < 100) { *o++ = DIG2S[2 * v]; *o++ = DIG2S[2 * v + 1]; }
            else if (v < 1000) { *o++ = (char)('0' + v / 100); u32 r = v % 100; *o++ = DIG2S[2 * r]; *o++ = DIG2S[2 * r + 1]; }
            else { u32 h = v / 100; *o++ = DIG2S[2 * h]; *o++ = DIG2S[2 * h + 1]; u32 r = v - h * 100; *o++ = DIG2S[2 * r]; *o++ = DIG2S[2 * r + 1]; }
        } else {
            u32 hi = v / 10000, lo = v - hi * 10000;
            if (hi < 10) *o++ = (char)('0' + hi);
            else if (hi < 100) { *o++ = DIG2S[2 * hi]; *o++ = DIG2S[2 * hi + 1]; }
            else if (hi < 1000) { *o++ = (char)('0' + hi / 100); u32 r = hi % 100; *o++ = DIG2S[2 * r]; *o++ = DIG2S[2 * r + 1]; }
            else { u32 h2 = hi / 100; *o++ = DIG2S[2 * h2]; *o++ = DIG2S[2 * h2 + 1]; u32 r = hi - h2 * 100; *o++ = DIG2S[2 * r]; *o++ = DIG2S[2 * r + 1]; }
            const char *d = DIG4 + 4 * lo;
            *o++ = d[0]; *o++ = d[1]; *o++ = d[2]; *o++ = d[3];
        }
        *o++ = (i + 1 == lc) ? '\n' : ' ';
        if (o >= oend) { fwrite(outbuf, 1, (size_t)(o - outbuf), stdout); o = outbuf; }
    }
    fwrite(outbuf, 1, (size_t)(o - outbuf), stdout);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #13.863 ms4 MB + 68 KBAcceptedScore: 100

Subtask #1 Testcase #24.8 ms6 MB + 116 KBAcceptedScore: 0

Subtask #1 Testcase #34.219 ms4 MB + 796 KBAcceptedScore: 0

Subtask #1 Testcase #44.284 ms4 MB + 784 KBAcceptedScore: 0

Subtask #1 Testcase #53.863 ms4 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #63.864 ms4 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #73.861 ms4 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #84.589 ms5 MB + 804 KBAcceptedScore: 0

Subtask #1 Testcase #94.631 ms5 MB + 804 KBAcceptedScore: 0

Subtask #1 Testcase #104.455 ms5 MB + 468 KBAcceptedScore: 0

Subtask #1 Testcase #114.862 ms6 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #124.28 ms5 MB + 76 KBAcceptedScore: 0

Subtask #1 Testcase #133.862 ms4 MB + 68 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-29 17:42:36 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠