Div1-Mediumはこれですよ http://t.co/2fixl1Bo55
— *IRUN (@ir5) 2014, 1月 30
class EllysPairing { public: int getMax(int M, vector <int> count, vector <int> first, vector <int> mult, vector <int> add) { int N=count.size(); int co=0; ll maj=-1; REP(i, N) { uint32_t v = first[i]; REP(loop, count[i]) { if(v==maj) co++; else if(co==0) maj=v,co=1; else co--; v = (v * mult[i] + add[i]) & (M-1); } } co=0; REP(i, N) { uint32_t v = first[i]; REP(loop, count[i]) { if(maj==v) co++; v = (v * mult[i] + add[i]) & (M-1); } } int total=accumulate(ALL(count), 0); int th = total/2; if(co>th) { int rest = (co-th) - (total-th*2); th-=rest; } return th; } };
int h[(1<<16)+1]; class EllysPairing { public: int getMax(int M, vector <int> count, vector <int> first, vector <int> mult, vector <int> add) { int N=count.size(); CLEAR(h, 0); REP(i, N) { VI w; uint32_t v = first[i]; REP(loop, count[i]) { h[v&((1<<16)-1)]++; v = (v * mult[i] + add[i]) & (M-1); } } ll lo=-1, loi=-1; REP(i, 1<<16) if(lo<h[i]){lo=h[i];loi=i;} CLEAR(h, 0); REP(i, N) { VI w; uint32_t v = first[i]; REP(loop, count[i]) { h[v>>16]++; v = (v * mult[i] + add[i]) & (M-1); } } ll hi=-1, hii=-1; REP(i, 1<<16) if(hi<h[i]){hi=h[i];hii=i;} int maj = (hii<<16)+loi, mx=0; REP(i, N) { VI w; uint32_t v = first[i]; REP(loop, count[i]) { if(v==maj) mx++; v = (v * mult[i] + add[i]) & (M-1); } } int total=accumulate(ALL(count), 0); int th = total/2; if(mx>th) { int rest = (mx-th) - (total-th*2); th-=rest; // cout<<"--- "<<rest<<endl; } return th; } };