/* rdfs1880.c -- route 73's constructive maximiser (job #1880), second design after the residue local search failed its controls: randomised depth-first construction with restarts and a node budget per restart. Wang's position convention (positions j = 1, 2, ..., pair (6j-1, 6j+1); prime p with residue r kills j iff j = r or j + pskip_p = r (mod p), 6 pskip_p = 2 (mod p)). Each restart: start from no residues; at the first uncovered position j*, the candidates are (unused prime p, residue r in {j* mod p, (j* + pskip_p) mod p}); order them by newly covered positions in the window [1, jmax] plus random jitter; recurse; stop the restart after `nodecap` nodes. Best run (first uncovered - 1) kept; residues printed as JSON for an independent verifier (maximiser1880.Instance.verify). usage: rdfs1880 n seconds seed target jmax nodecap [mode] [H] */ #include #include #include #include #include #define MAXP 32 #define MAXW 64 static int np, P[MAXP], SK[MAXP], jmax, W; static uint64_t mask[MAXP][100][MAXW]; /* mask[i][r][w] */ static int used[MAXP], res[MAXP], bestres[MAXP], best = 0, target, mode = 0, H = 30; static long long nodes, nodecap, totalnodes = 0; static int restarts = 0; static clock_t t0; static uint64_t rng_s[2]; static uint64_t rnd(void){ uint64_t s1=rng_s[0], s0=rng_s[1]; rng_s[0]=s0; s1^=s1<<23; rng_s[1]=s1^s0^(s1>>17)^(s0>>26); return rng_s[1]+s0; } static int isprime(int n){ if(n<2) return 0; for(int d=2; d*d<=n; d++) if(n%d==0) return 0; return 1; } static int first_zero(const uint64_t *cov){ for(int w=0; w>(j%64)&1) && !(cov[j/64]>>(j%64)&1)) c++; return c; } /* mode 0: newly covered positions in the whole window; 1: pure random; 2: newly covered positions within H positions ahead; 3: smaller primes first; 4: larger primes first (all with random jitter) */ static long long keyof(const uint64_t *cov, int i, int r, int jz){ switch(mode){ case 0: return (long long)popc_new(cov, mask[i][r])*1000 + (long long)(rnd()%3000); case 1: return (long long)(rnd()%1000000); case 2: return (long long)popc_near(cov, mask[i][r], jz)*1000 + (long long)(rnd()%1500); case 3: return -(long long)P[i]*1000 + (long long)(rnd()%6000); default: return (long long)P[i]*1000 + (long long)(rnd()%6000); } } typedef struct { int i, r; long long key; } cand_t; static int cmpc(const void *a, const void *b){ long long ka=((const cand_t*)a)->key, kb=((const cand_t*)b)->key; return kakb ? -1 : 0; } static void report(double t){ fprintf(stderr, "{\"t\": %.1f, \"restart\": %d, \"run\": %d, \"length\": %d}\n", t, restarts, best, 6*best+5); } static void dfs(uint64_t *cov, int depth){ if(nodes >= nodecap) return; int jz = first_zero(cov); /* 0-based index of first uncovered = run length in positions */ if(jz > best){ best = jz; memcpy(bestres, res, sizeof(res)); report((double)(clock()-t0)/CLOCKS_PER_SEC); } if(jz >= jmax || depth == np) return; int pos = jz + 1; /* 1-based position */ cand_t c[2*MAXP]; int nc = 0; for(int i=0; i= target/6) return; /* target reached: unwind */ } } int main(int argc, char **argv){ int n = atoi(argv[1]); double seconds = atof(argv[2]); uint64_t seed = strtoull(argv[3],0,10); target = atoi(argv[4]); jmax = atoi(argv[5]); nodecap = atoll(argv[6]); if(argc>7) mode = atoi(argv[7]); if(argc>8) H = atoi(argv[8]); rng_s[0] = seed*0x9E3779B97F4A7C15ULL + 1; rng_s[1] = seed ^ 0xD1B54A32D192ED03ULL; for(int i=0;i<20;i++) rnd(); int cnt=0, q=2; np=0; while(cnt=5){ P[np]=q; np++; } } q++; } W = (jmax+63)/64; if(W>MAXW || np>MAXP){ fprintf(stderr,"limits\n"); return 1; } for(int i=0;i= target */ target = 6*tgt_run; /* dfs compares best >= target/6 = tgt_run */ t0 = clock(); uint64_t cov0[MAXW]; memset(cov0,0,sizeof(cov0)); while((double)(clock()-t0)/CLOCKS_PER_SEC < seconds && best < tgt_run){ restarts++; nodes = 0; for(int i=0;i