// C++11 #define _DEBUG #define DEBUG2 #define _DEBUG3 #include #include #include #include #include #include "bits/stdc++.h" #include #include #include #include using namespace std; inline long long GetTSC() { long long lo, hi; asm volatile ("rdtsc": "=a"(lo), "=d"(hi)); return lo + (hi << 32); } inline double GetSeconds() { return GetTSC() / 2.8e9; } class XRand { public: unsigned int x, y, z, w; const int DC = pow(2, 27); XRand() { init(); } void init() { x = 314159261; y = 358979323; z = 846264338; w = 327950288; } unsigned int next() { unsigned int t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } int nextInt(int m) { return (int)(next() % m); } double nextDouble() { return double(next() % DC) / DC; } }; const double TO = 0.85; const int NM = 60; const int NMM = NM * NM; const int KM = 500; bitset A; bitset mask[26][NMM * 2]; int mi[26]; int RI[KM]; int L[KM]; int R[KM][4]; double starttime, gt; XRand rnd = XRand(); #ifdef DEBUG struct XorShift { uint64_t x = 88172645463325252ULL; XorShift() {} void setSeed(uint64_t seed) { x = seed; } uint64_t next() { x ^= x << 13; x ^= x >> 7; x ^= x << 17; return x; } int nextInt(int n) { uint64_t upper = 0xFFFFFFFFFFFFFFFFULL / n * n; uint64_t v = next(); while (v >= upper) { v = next(); } return v % n; } double nextDouble() { uint64_t v = next() >> 11; // 53bit return (double)v / (1ULL << 53); } }; XorShift xs; int p_seed; bitset p_a; bitset p_a_init; int p_l[KM]; class PlayMachine { public: static void init(int i){ p_seed = i; xs.setSeed(p_seed); p_a_init.reset(); p_a.reset(); for(int i=0; i> n >> k; for(int i=0; i> L[i]; } for(int i=0; i> s; for(int j=0; j 1){ ma[mi[i]].reset(); for(int l=0; l0; l--){ auto ma = mask[l]; int mm = mi[l]; for(int i=0; i tm){ tm = tc; ti = j; } } RI[i] = ti; A ^= ma[RI[i]]; } } int cc = A.count(); #ifdef DEBUG2 cerr << "bcc: " << cc << endl; #endif int tt = 0; while(1){ double gt = (GetSeconds() - starttime) / TO; if(gt >= 1.0) break; int i = tt % KM; int l = L[i]; int ri = RI[i]; auto ma = mask[l]; int mii = mi[l]; int ni = rnd.nextInt(mii - 1); if(ni >= ri) ni++; int nc = (A ^ ma[ri] ^ ma[ni]).count(); if(nc <= cc || rnd.nextDouble() / pow(nc - cc, 2) > gt){ RI[i] = ni; cc = nc; A ^= ma[ri] ^ ma[ni]; }else{ } tt++; } #ifdef DEBUG2 cerr << "acc: " << cc << endl; #endif // output for(int i=0; i