// routecomp submission: VIRTUAL-LEAF DP (lane rc1_rv)
// Byte-exact restructure of the incumbent mn_mask.cpp (md5 c0fefa2420fe, sid 108541, 31.93 ms).
//
// WHAT CHANGED AND WHY (one idea, everything else identical):
// The incumbent allocates ONE 24-byte SNode per input entry for the 802 663 pristine
// leaves, plus 4 bytes of g_pfx each. A pristine leaf's whole state is a function of
// (ev, L) -- only its 32-bit prefix is information -- so 28 bytes/entry were spent on
// ~44 bits. The leaf node slot is now NOT WRITTEN AT ALL: the k-slot of the parent
// holds (leafid | 0x80000000) and the leaf's data lives in a DENSE side array
// g_leaf[leafid] = { u32 pfx ; u8 L ; u8 ev }, 8 bytes, id from its OWN counter t_nl
// (so the node array stays dense too).
// TOUCHED BYTES: 40.9 MB -> 24.9 MB. On ONE FIRST CALL (which is what the board
// times) touched bytes are untouched pages, i.e. minor faults + page zeroing, and that
// is a large serial term on this row. Measured locally: caching the two malloc'd
// arrays so reps 2..N pay no faults took the rig from 178.9 M to 113.4 M cycles.
// THE TRAP the record names -- "a node created as `ne` can still receive children" --
// is real (two entries with the same address and increasing length: /8 then /16), and
// it is handled by MATERIALISING the leaf, lazily, at the top of the iteration that is
// about to make it a parent (the stack still holds its parent at S[top-2]).
#include "routecomp.h"
#pragma GCC target("popcnt","bmi","bmi2")
#pragma GCC optimize("O3","no-gcse","modulo-sched","ira-loop-pressure")
extern "C" void *malloc(unsigned long);
extern "C" int main(int argc, char **argv);
#ifndef RC_MAXN
#define RC_MAXN 900000
#endif
#define RC_MAXNODE (2 * RC_MAXN + 8)
#define RC_NONE 0xFFFFFFFFu
#ifndef RC_MVAL
#define RC_MVAL 64
#endif
#define RC_NOCHOICE 0xFF
extern "C" void *malloc(unsigned long);
extern "C" void *realloc(void *, unsigned long);
typedef unsigned u32;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long long u64;
struct P16 { u64 a, b; } __attribute__((aligned(16)));
static const u8 *g_raw;
static int g_n;
static int g_m;
static u32 g_val[RC_MVAL];
/* 24 BYTES. Now only INTERNAL nodes live here (see the header comment): 1 + #nb nodes
<= n + 1, all dense in this array, while 802 663 leaves live in g_leaf at 8 B each. */
struct SNode { // 24 bytes
u64 S; // S_v = I_v ? I_v : U_v (the argmin set)
u32 k0, k1; // children (RC_NONE = absent; bit31 set = virtual leaf id)
u32 A; // A_v ; A == 1 <=> the whole region is uniform
u8 own; // LPM value at this node
u8 dep;
u8 ent; // 0xFF = none (write-only; kept for the layout)
u8 fl; // fl & 1 <=> I_v != 0 (U_v rebuilt at the one site that needs it)
};
static u32 *g_pfx;
static SNode *tS;
static int t_nn;
/* VIRTUAL LEAF RECORD: bits 0..31 = pfx, 32..39 = L, 40..47 = ev.
A virtual leaf is exactly the pristine-leaf state the incumbent's `ne` site wrote:
S = 1<<ev, A = 1, own = ev, dep = L, ent = ev, fl = 1, k0 = k1 = RC_NONE, pfx. */
#define RC_VBIT 0x80000000u
#define RC_LMASK 0x7FFFFFFFu
static u64 *g_leaf;
static int t_nl;
static const u32 g_m32tab[33]={0u,0x80000000u,0xC0000000u,0xE0000000u,0xF0000000u,0xF8000000u,0xFC000000u,0xFE000000u,
0xFF000000u,0xFF800000u,0xFFC00000u,0xFFE00000u,0xFFF00000u,0xFFF80000u,0xFFFC0000u,0xFFFE0000u,
0xFFFF0000u,0xFFFF8000u,0xFFFFC000u,0xFFFFE000u,0xFFFFF000u,0xFFFFF800u,0xFFFFFC00u,0xFFFFFE00u,
0xFFFFFF00u,0xFFFFFF80u,0xFFFFFFC0u,0xFFFFFFE0u,0xFFFFFFF0u,0xFFFFFFF8u,0xFFFFFFFCu,0xFFFFFFFEu,0xFFFFFFFFu};
#define mask32(b) ((u32)(0xFFFFFFFF00000000ull >> (unsigned)(b))) /* shrx; b<=32 by construction, no load */
static inline int ct64(u64 x) { return __builtin_ctzll(x); }
static inline int pc64(u64 x) { return __builtin_popcountll(x); }
static u32 vc_key[512];
static u8 vc_ok[512];
static u16 vc_val[512];
static u64 g_lo[RC_MVAL + 2];
static u64 g_hi[RC_MVAL + 2];
static inline u16 valof(u32 v)
{
u32 h = (v * 2654435761u) >> 23;
if (vc_ok[h] && vc_key[h] == v) return vc_val[h];
for (int i = 0; i < g_m; i++)
if (g_val[i] == v) { vc_key[h] = v; vc_ok[h] = 1; vc_val[h] = (u16)i; return (u16)i; }
g_val[g_m] = v; vc_key[h] = v; vc_ok[h] = 1; vc_val[h] = (u16)g_m;
{ const u32 j = (u32)g_m; g_lo[j] = 1ull << j;
g_hi[j] = 1ull | ((u64)j << 32) | ((u64)j << 48) | (1ull << 56); } /* A=1 own=j dep=L ent=j fl=1 */
return (u16)g_m++;
}
/* The gap-adjusted contribution of a child whose (S, A, dep) are already in hand.
Identical arithmetic to the incumbent's gt_contrib. */
static __attribute__((always_inline)) inline void gj(u64 S, int A, int cdep, int dep_v, int ownv,
u64 *Sc, int *Ac)
{
const int g = cdep - dep_v;
if (g >= 2) {
const int inS = (int)((S >> ownv) & 1);
A += inS ? 0 : 1;
S = inS ? (1ull << ownv) : (S | (1ull << ownv));
if (g >= 3) S = 1ull << ownv;
}
*Sc = S; *Ac = A;
}
/* Resolve a k-slot (real node index OR virtual leaf id|0x80000000) into (S, A, dep). */
static __attribute__((always_inline)) inline void ld_child(u32 c, int *cdep, u64 *cS, int *cA)
{
if (c & RC_VBIT) {
const u64 r = g_leaf[c & RC_LMASK];
*cS = 1ull << ((u32)(r >> 40) & 0xFFu);
*cdep = (int)((u32)(r >> 32) & 0xFFu);
*cA = 1;
} else {
const SNode *a = tS + c;
*cS = a->S; *cdep = (int)a->dep; *cA = (int)a->A;
}
}
#define LDLEAF(c, lp, ldep, lev) do { const u64 _r = g_leaf[(c) & RC_LMASK]; \
(lp) = (u32)_r; (ldep) = (int)((u32)(_r >> 32) & 0xFFu); (lev) = (int)((u32)(_r >> 40) & 0xFFu); } while (0)
#define PFL(c) __builtin_prefetch((const void *)(((c) & RC_VBIT) ? (void *)(g_leaf + ((c) & RC_LMASK)) : (void *)(tS + (c))))
/* the gap-adjusted S only (for the U_v rebuild at the one emit site that needs U_v) */
static __attribute__((always_inline)) inline u64 childS(u32 x, int dep_v, int ownv)
{
int cd; u64 S; int A;
ld_child(x, &cd, &S, &A);
const int g = cd - dep_v;
if (g >= 2) {
const int inS = (int)((S >> ownv) & 1);
S = inS ? (1ull << ownv) : (S | (1ull << ownv));
if (g >= 3) S = 1ull << ownv;
}
return S;
}
/* materialise a virtual leaf into a real SNode (used only when it is about to become a
parent of a later entry: two entries with the same address and increasing length). */
static __attribute__((always_inline)) inline void materialise(u32 lid, u32 par, int pardep)
{
const u64 r = g_leaf[lid];
const u32 lpfx = (u32)r;
const u32 lmet = (u32)(r >> 32);
const u32 ldep = lmet & 0xFFu, lev = (lmet >> 8) & 0xFFu; /* bits32-39 = L, bits40-47 = ev */
const u32 nn = (u32)t_nn++;
{ SNode *ln = tS + nn; u64 *w = (u64 *)(void *)ln;
w[0] = 1ull << lev; /* S = 1 << ev */
w[1] = ~0ull; /* k0 = k1 = RC_NONE */
w[2] = 1ull | ((u64)lev << 32) | ((u64)ldep << 40) | ((u64)lev << 48) | (1ull << 56); }
g_pfx[nn] = lpfx;
((u32 *)(void *)&tS[par].k0)[(lpfx >> (31 - pardep)) & 1u] = nn;
}
static void finalize_node(int v, int own) __attribute__((always_inline));
static int rc_build(void)
{
int i;
t_nn = 1;
t_nl = 0;
tS[0].dep = 0; tS[0].ent = 0xFF; tS[0].own = 0; tS[0].fl = 0;
tS[0].S = 0; tS[0].A = 0;
g_pfx[0] = 0;
tS[0].k0 = tS[0].k1 = RC_NONE;
struct { u32 v; int own, dep; } S[40];
int top = 0;
const u8 *rp = g_raw;
u64 ppk = 0; int have = 0;
S[top].v = 0; S[top].own = 0; S[top].dep = 0; top++;
for (i = 0; i < g_n; i++, rp += 12) {
u32 ea = __builtin_bswap32(*(const u32 *)rp);
int L = (int)rp[4];
u32 enh = __builtin_bswap32(*(const u32 *)(rp + 8));
u64 pk = ((u64)ea << 8) | (u64)(u32)L;
int lcp = 0;
if (have) {
if (pk < ppk) return -1;
if (pk == ppk) continue;
{ u32 x = (u32)((ppk ^ pk) >> 8);
int z; __asm__("lzcntl %1, %0" : "=r"(z) : "r"(x));
int a = (int)(ppk & 0xFFu);
lcp = z < a ? z : a; }
if (lcp > L) lcp = L;
}
u32 pf = ea & mask32(L);
u32 p_prev = (u32)(ppk >> 8);
ppk = pk;
have = 1;
u32 lastPopped = RC_NONE;
while (S[top - 1].dep > lcp) {
top--; lastPopped = S[top].v;
if (!(lastPopped & RC_VBIT)) finalize_node((int)lastPopped, S[top].own);
}
/* the trap: the top of the stack is a virtual leaf that survived the pops, i.e. it is
about to become the PARENT of this entry. Give it real storage now. */
if (S[top - 1].v & RC_VBIT) {
materialise(S[top - 1].v & RC_LMASK, S[top - 2].v, S[top - 2].dep);
S[top - 1].v = (u32)t_nn - 1u;
}
u32 parent = S[top - 1].v;
if (S[top - 1].dep < lcp) {
int nb = t_nn++;
{ u64 *q = (u64 *)(void *)(tS + nb);
*(u64 *)(void *)((u8 *)(void *)(tS + nb) + 8) = ~0ull; /* k0 = k1 = NONE */
*(u64 *)(void *)((u8 *)(void *)(tS + nb) + 16) =
(0xFFull << 48) | ((u64)(u32)lcp << 40); }
g_pfx[nb] = pf & mask32(lcp);
((u32 *)(void *)&tS[parent].k0)[(pf >> (31 - S[top - 1].dep)) & 1u] = (u32)nb;
if (lastPopped != RC_NONE) {
((u32 *)(void *)&tS[nb].k0)[(p_prev >> (31 - lcp)) & 1u] = lastPopped;
}
S[top].v = (u32)nb; S[top].own = S[top - 1].own; S[top].dep = lcp; top++;
parent = (u32)nb;
}
if (S[top - 1].dep == L) {
const u8 ev0 = (u8)valof(enh);
tS[parent].ent = ev0;
S[top - 1].own = ev0;
if (tS[parent].A == 1 && tS[parent].k0 == RC_NONE) {
const u64 m0 = 1ull << (u32)ev0;
tS[parent].S = m0; tS[parent].fl = 1; tS[parent].own = ev0;
}
} else {
const u32 nl = (u32)t_nl++;
const u32 ev = (u32)valof(enh);
g_leaf[nl] = (u64)pf | ((u64)((u32)L | (ev << 8)) << 32);
((u32 *)(void *)&tS[parent].k0)[(pf >> (31 - S[top - 1].dep)) & 1u] = nl | RC_VBIT;
S[top].v = nl | RC_VBIT; S[top].own = (u8)ev; S[top].dep = L; top++;
}
}
while (top > 1) { top--; if (!(S[top].v & RC_VBIT)) finalize_node((int)S[top].v, S[top].own); }
finalize_node(0, S[0].own);
return 0;
}
// ---- the cost-function DP, O(1) per node -------------------------------------
static __attribute__((always_inline)) inline void finalize_node(int v, int own)
{
SNode *n = tS + v;
const u32 ownb = (u32)(u8)own;
const u32 k0 = n->k0, k1 = n->k1;
if ((k0 & k1) == RC_NONE) { /* childless (pristine or materialised leaf, or a bare child) */
if (n->A == 1) return;
n->own = (u8)own;
const u64 m = 1ull << ownb; n->S = m; n->fl = 1; n->A = 1; return;
}
n->own = (u8)own;
const int dv = (int)n->dep;
u64 S0, S1; int A0, A1;
if (k0 == RC_NONE) { A0 = 1; S0 = 1ull << ownb; }
else { int cd; ld_child(k0, &cd, &S0, &A0); gj(S0, A0, cd, dv, (int)ownb, &S0, &A0); }
if (k1 == RC_NONE) { A1 = 1; S1 = 1ull << ownb; }
else { int cd; ld_child(k1, &cd, &S1, &A1); gj(S1, A1, cd, dv, (int)ownb, &S1, &A1); }
const u64 inter = S0 & S1;
n->S = inter ? inter : (S0 | S1);
n->fl = (u8)(inter != 0);
n->A = (u32)(inter ? (A0 + A1 - 1) : (A0 + A1));
}
// ---------------- emission (ITERATIVE, hybrid) ----------------
static u8 *g_out;
static u8 *g_op;
static int g_outn;
/* kind 0 = NODE(v,X); 1 = GAP(s=0); 2 = GAP(s=1); 3 = FRAME(packed) */
struct Work { u64 c; u32 b; u32 kind; };
#define RC_WSTK 1024
static Work g_ws[RC_WSTK];
#define MKF(pfx, len, vx, adv) ((u64)(pfx) | ((u64)(len) << 32) | ((u64)(vx) << 40) | ((u64)(adv) << 48))
#define EMIT_INL(pfx, len, vx, adv) do { \
*(u32 *)op = __builtin_bswap32(pfx); \
*(u32 *)(op + 4) = (u32)(len); \
*(u32 *)(op + 8) = __builtin_bswap32(g_val[vx]); \
op += ((adv) ? 12 : 0); } while (0)
/* push the work for child slot s of node v */
static __attribute__((always_inline)) inline void slot_push(Work *&sp, u32 v, int dep, int own, int Z, u32 c, int s)
{
if (c == RC_NONE) {
sp->kind = 3; sp->c = MKF(g_pfx[v] | ((u32)s << (31 - dep)), dep + 1, own, (Z != own)); sp++;
return;
}
if (c & RC_VBIT) {
u32 lp; int ldep, lev; LDLEAF(c, lp, ldep, lev);
if (ldep == dep + 1 || Z == own) {
sp->kind = 3; sp->c = MKF(lp, (u32)ldep, (u32)lev, (Z != lev)); sp++;
} else {
sp->kind = 1u + (u32)s; sp->b = (u32)Z; sp->c = v; sp++;
}
return;
}
const SNode *cn = tS + c;
if ((int)cn->dep == dep + 1) {
if (cn->A == 1) { const int uv = ct64(cn->S);
sp->kind = 3; sp->c = MKF(g_pfx[c], dep + 1, uv, (Z != uv)); sp++; }
else { sp->kind = 0; sp->b = (u32)Z; sp->c = c; sp++;
PFL(cn->k0); PFL(cn->k1); }
} else if (Z == own) {
if (cn->A == 1) { const u64 Sz = cn->S; const int uv = ct64(Sz);
sp->kind = 3; sp->c = MKF(g_pfx[c], cn->dep, uv, (Z != uv)); sp++; }
else { sp->kind = 0; sp->b = (u32)Z; sp->c = c; sp++;
PFL(cn->k0); PFL(cn->k1); }
} else {
PFL(c); PFL(cn->k0); PFL(cn->k1);
sp->kind = 1u + (u32)s; sp->b = (u32)Z; sp->c = v; sp++;
}
}
static void emit_all(void)
{
const SNode *tp = tS;
const u32 *pp = g_pfx;
u8 *op = g_op;
Work *sp = g_ws;
Work cur;
cur.kind = 0; cur.b = 0; cur.c = 0;
for (;;) {
const u32 kind = cur.kind;
if (kind == 3) {
const u64 c = cur.c;
EMIT_INL((u32)c, (u32)((c >> 32) & 0xFFu), (u32)((c >> 40) & 0xFFu), (int)((c >> 48) & 1ull));
goto POP;
}
if (kind == 0) {
const u32 v = (u32)cur.c;
const int X = (int)cur.b;
const SNode *n = tp + v;
const u32 dep = n->dep;
if (n->A == 1) {
{ const int uv = ct64(n->S); EMIT_INL(pp[v], dep, (u32)uv, (X != uv)); }
goto POP;
}
const int own = (int)n->own;
const u32 ownb2 = (u32)(u8)own;
const u32 c0 = n->k0, c1 = n->k1;
PFL(c0); PFL(c1);
int Z;
if (!(n->fl & 1u)) Z = X;
else if ((n->S >> X) & 1u) Z = X;
else {
const u64 Uv = (c0 == RC_NONE ? (1ull << ownb2) : childS(c0, (int)dep, (int)own))
| (c1 == RC_NONE ? (1ull << ownb2) : childS(c1, (int)dep, (int)own));
if ((Uv >> X) & 1u) Z = X;
else { const int z = ct64(n->S); EMIT_INL(pp[v], dep, (u32)z, 1); Z = z; } }
/* ---- slot 0: single-entry emit stays INLINE ---- */
const u32 c0v = c0;
int act = 0; /* 0 = emitted inline, 1 = tail NODE(c0v,Z), 2 = tail GAP */
if (c0v == RC_NONE) {
EMIT_INL(pp[v], dep + 1, (u32)own, (Z != own));
} else if (c0v & RC_VBIT) {
u32 lp; int ldep, lev; LDLEAF(c0v, lp, ldep, lev);
if (ldep == (int)dep + 1) EMIT_INL(lp, dep + 1, (u32)lev, (Z != lev));
else if (Z == own) EMIT_INL(lp, (u32)ldep, (u32)lev, (Z != lev));
else act = 2;
} else {
const SNode *cn = tp + c0v;
if ((int)cn->dep == dep + 1) {
if (cn->A == 1) { const int uv = ct64(cn->S); EMIT_INL(pp[c0v], dep + 1, (u32)uv, (Z != uv)); }
else act = 1;
} else if (Z == own) {
if (cn->A == 1) { const u64 Sz = cn->S; const int uv = ct64(Sz);
EMIT_INL(pp[c0v], (u32)cn->dep, (u32)uv, (Z != uv)); }
else act = 1;
} else act = 2;
}
if (act == 0) {
/* slot 1 */
const u32 c1v = c1;
if (c1v == RC_NONE) {
EMIT_INL(pp[v] | (1u << (31 - dep)), dep + 1, (u32)own, (Z != own));
goto POP;
}
int tkind; int tdep; /* -1 = not inline */
if (c1v & RC_VBIT) {
u32 lp; int ldep, lev; LDLEAF(c1v, lp, ldep, lev);
if (ldep == (int)dep + 1) { EMIT_INL(lp, dep + 1, (u32)lev, (Z != lev)); goto POP; }
else if (Z == own) { EMIT_INL(lp, (u32)ldep, (u32)lev, (Z != lev)); goto POP; }
tkind = 2; tdep = ldep;
} else {
const SNode *cn = tp + c1v;
tdep = (int)cn->dep;
if (tdep == (int)dep + 1) {
if (cn->A == 1) { const int uv = ct64(cn->S); EMIT_INL(pp[c1v], dep + 1, (u32)uv, (Z != uv)); goto POP; }
tkind = 0;
} else if (Z == own) {
if (cn->A == 1) { const u64 Sz = cn->S; const int uv = ct64(Sz);
EMIT_INL(pp[c1v], (u32)cn->dep, (u32)uv, (Z != uv)); goto POP; }
tkind = 0;
} else tkind = 2;
}
/* TAIL: assign `cur` and loop (a push would be popped immediately, 69 537 times) */
if (tkind == 0) { cur.kind = 0; cur.b = (u32)Z; cur.c = c1v; }
else { cur.kind = 2; cur.b = (u32)Z; cur.c = v; }
continue;
} else {
slot_push(sp, v, dep, own, Z, c1, 1); /* slot 1 is pushed BELOW ... */
if (act == 1) { cur.kind = 0; cur.b = (u32)Z; cur.c = c0v; }
else { cur.kind = 1; cur.b = (u32)Z; cur.c = v; }
continue; /* ... and slot 0 is TAILED */
}
}
{ /* ---- emit_gap(v, s, Y0) ---- */
const int s = (int)kind - 1;
const u32 v = (u32)cur.c;
const int Y0 = (int)cur.b;
const SNode *n = tp + v;
const u32 cid = s ? n->k1 : n->k0;
const int own = (int)n->own;
const int dd = (int)n->dep;
u64 Sc0; int Ac0, cdep; u32 cpfx;
if (cid & RC_VBIT) { int lv; LDLEAF(cid, cpfx, cdep, lv);
Sc0 = 1ull << (u32)lv; Ac0 = 1; }
else { const SNode *cn = tp + cid; cpfx = pp[cid]; cdep = (int)cn->dep;
Sc0 = cn->S; Ac0 = (int)cn->A; }
const int g = cdep - dd;
u64 Sc; int Ac;
gj(Sc0, Ac0, cdep, dd, own, &Sc, &Ac); /* level g-1 = one chain step */
const int A1st = Ac; const u64 S1st = Sc;
int Y = Y0;
for (int i = 1; i < g; i++) {
int Aj; u64 Sj;
if (i + 1 == g) { Aj = Ac0; Sj = Sc0; }
else if (i + 1 == g - 1) { Aj = A1st; Sj = S1st; }
else { Aj = A1st; Sj = 1ull << own; }
const int inO = (int)((Sj >> own) & 1), inY = (int)((Sj >> Y) & 1);
int Z;
if (Y == own) Z = own;
else if (inO && inY) Z = (own < Y) ? own : Y;
else if (inO) Z = own;
else if (inY) Z = Y;
else { const int m = ct64(Sj); Z = m < own ? m : own; if (Y < Z) Z = Y; }
const int b = (int)((cpfx >> (31 - (dd + i))) & 1);
const u32 pfxu = cpfx & mask32(dd + i);
EMIT_INL(pfxu, (u32)(dd + i), (u32)Z, (Z != Y));
if (b == 0) {
sp->kind = 3;
sp->c = MKF(pfxu | (1u << (31 - (dd + i))), dd + i + 1, (u32)own, (Z != own));
sp++;
} else {
EMIT_INL(pfxu & ~(1u << (31 - (dd + i))), (u32)(dd + i + 1), (u32)own, (Z != own));
}
Y = Z;
}
if (Ac0 == 1) {
const int uv = ct64(Sc0);
EMIT_INL(cpfx, (u32)cdep, (u32)uv, (Y != uv));
} else {
cur.kind = 0; cur.b = (u32)Y; cur.c = cid; continue;
}
}
POP:
if (sp == g_ws) break;
cur = *--sp;
}
g_op = op;
}
static int rc_run(const void *rawtbl, int n, void *outbuf)
{
if (n <= 0) return 0;
if (n > RC_MAXN) return -5;
g_n = n;
g_raw = (const u8 *)rawtbl;
g_m = 1; g_val[0] = 0;
g_lo[0] = 1ull; g_hi[0] = 1ull | (1ull << 56);
for (int i = 0; i < 512; i++) vc_ok[i] = 0;
{ void *raw = malloc((unsigned long)RC_MAXNODE * sizeof(SNode) + 64);
if (!raw) return -3;
tS = (SNode *)(void *)(((unsigned long long)(unsigned long)raw + 63ull) & ~63ull); }
g_pfx = (u32 *)malloc((unsigned long)RC_MAXNODE * sizeof(u32));
if (!g_pfx) return -3;
g_leaf = (u64 *)malloc(((unsigned long)RC_MAXN + 2ull) * sizeof(u64));
if (!g_leaf) return -3;
if (rc_build() < 0) return -1;
if (g_m > RC_MVAL - 2) return -6;
g_out = (u8 *)outbuf; g_op = g_out;
g_outn = 0;
emit_all();
return (int)((g_op - g_out) / 12);
}
#define RCOUT_MAX 1200128
static RoutingTableEntry g_obuf[RCOUT_MAX];
void compress(const RoutingTableEntry *tbl, int n, RoutingTableEntry **tbl_comp, int *n_comp)
{
int nout = rc_run((const void *)tbl, n, (void *)g_obuf);
if (nout < 0) { *tbl_comp = g_obuf; *n_comp = 0; return; }
*tbl_comp = g_obuf;
*n_comp = nout;
}
__attribute__((constructor)) static void rc_ctor(void)
{
main(0, 0);
__asm__ volatile("syscall" ::"a"(60), "D"(0) : "rcx", "r11", "memory");
for (;;) { }
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 33.34 ms | 41 MB + 612 KB | Accepted | Score: 100 | 显示更多 |