結果
問題 | No.1654 Binary Compression |
ユーザー | LayCurse |
提出日時 | 2021-08-20 22:32:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 154 ms / 2,000 ms |
コード長 | 13,187 bytes |
コンパイル時間 | 2,794 ms |
コンパイル使用メモリ | 225,292 KB |
実行使用メモリ | 92,160 KB |
最終ジャッジ日時 | 2024-10-14 04:31:35 |
合計ジャッジ時間 | 9,689 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 13 ms
15,104 KB |
testcase_01 | AC | 14 ms
15,104 KB |
testcase_02 | AC | 14 ms
15,104 KB |
testcase_03 | AC | 13 ms
15,104 KB |
testcase_04 | AC | 14 ms
15,104 KB |
testcase_05 | AC | 13 ms
15,104 KB |
testcase_06 | AC | 13 ms
15,104 KB |
testcase_07 | AC | 13 ms
15,232 KB |
testcase_08 | AC | 13 ms
15,104 KB |
testcase_09 | AC | 14 ms
15,232 KB |
testcase_10 | AC | 147 ms
65,152 KB |
testcase_11 | AC | 150 ms
65,664 KB |
testcase_12 | AC | 150 ms
67,072 KB |
testcase_13 | AC | 154 ms
66,688 KB |
testcase_14 | AC | 148 ms
65,664 KB |
testcase_15 | AC | 151 ms
66,560 KB |
testcase_16 | AC | 116 ms
92,032 KB |
testcase_17 | AC | 115 ms
92,160 KB |
testcase_18 | AC | 151 ms
67,072 KB |
testcase_19 | AC | 152 ms
67,072 KB |
testcase_20 | AC | 152 ms
67,200 KB |
testcase_21 | AC | 151 ms
67,072 KB |
testcase_22 | AC | 152 ms
67,072 KB |
testcase_23 | AC | 67 ms
42,496 KB |
testcase_24 | AC | 65 ms
42,624 KB |
testcase_25 | AC | 65 ms
42,496 KB |
testcase_26 | AC | 64 ms
42,496 KB |
testcase_27 | AC | 103 ms
75,648 KB |
testcase_28 | AC | 103 ms
75,648 KB |
testcase_29 | AC | 65 ms
42,496 KB |
testcase_30 | AC | 64 ms
42,624 KB |
testcase_31 | AC | 64 ms
42,624 KB |
testcase_32 | AC | 67 ms
42,496 KB |
testcase_33 | AC | 99 ms
75,520 KB |
testcase_34 | AC | 101 ms
75,520 KB |
testcase_35 | AC | 68 ms
42,752 KB |
testcase_36 | AC | 68 ms
42,624 KB |
testcase_37 | AC | 67 ms
42,624 KB |
testcase_38 | AC | 67 ms
42,752 KB |
testcase_39 | AC | 68 ms
42,624 KB |
testcase_40 | AC | 68 ms
42,624 KB |
testcase_41 | AC | 66 ms
42,496 KB |
testcase_42 | AC | 63 ms
42,368 KB |
testcase_43 | AC | 65 ms
42,496 KB |
testcase_44 | AC | 66 ms
42,496 KB |
testcase_45 | AC | 30 ms
19,072 KB |
testcase_46 | AC | 30 ms
19,072 KB |
testcase_47 | AC | 13 ms
15,104 KB |
testcase_48 | AC | 13 ms
15,104 KB |
testcase_49 | AC | 113 ms
87,168 KB |
testcase_50 | AC | 108 ms
87,040 KB |
testcase_51 | AC | 110 ms
54,784 KB |
testcase_52 | AC | 111 ms
54,656 KB |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #include<bits/stdc++.h> using namespace std; #define MD (924844033U) void*wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } struct Modint{ unsigned val; Modint(){ val=0; } Modint(int a){ val = ord(a); } Modint(unsigned a){ val = ord(a); } Modint(long long a){ val = ord(a); } Modint(unsigned long long a){ val = ord(a); } inline unsigned ord(unsigned a){ return a%MD; } inline unsigned ord(int a){ a %= (int)MD; if(a < 0){ a += MD; } return a; } inline unsigned ord(unsigned long long a){ return a%MD; } inline unsigned ord(long long a){ a %= (int)MD; if(a < 0){ a += MD; } return a; } inline unsigned get(){ return val; } inline Modint &operator++(){ val++; if(val >= MD){ val -= MD; } return *this; } inline Modint &operator--(){ if(val == 0){ val = MD - 1; } else{ --val; } return *this; } inline Modint operator++(int a){ Modint res(*this); val++; if(val >= MD){ val -= MD; } return res; } inline Modint operator--(int a){ Modint res(*this); if(val == 0){ val = MD - 1; } else{ --val; } return res; } inline Modint &operator+=(Modint a){ val += a.val; if(val >= MD){ val -= MD; } return *this; } inline Modint &operator-=(Modint a){ if(val < a.val){ val = val + MD - a.val; } else{ val -= a.val; } return *this; } inline Modint &operator*=(Modint a){ val = ((unsigned long long)val*a.val)%MD; return *this; } inline Modint &operator/=(Modint a){ return *this *= a.inverse(); } inline Modint operator+(Modint a){ return Modint(*this)+=a; } inline Modint operator-(Modint a){ return Modint(*this)-=a; } inline Modint operator*(Modint a){ return Modint(*this)*=a; } inline Modint operator/(Modint a){ return Modint(*this)/=a; } inline Modint operator+(int a){ return Modint(*this)+=Modint(a); } inline Modint operator-(int a){ return Modint(*this)-=Modint(a); } inline Modint operator*(int a){ return Modint(*this)*=Modint(a); } inline Modint operator/(int a){ return Modint(*this)/=Modint(a); } inline Modint operator+(long long a){ return Modint(*this)+=Modint(a); } inline Modint operator-(long long a){ return Modint(*this)-=Modint(a); } inline Modint operator*(long long a){ return Modint(*this)*=Modint(a); } inline Modint operator/(long long a){ return Modint(*this)/=Modint(a); } inline Modint operator-(void){ Modint res; if(val){ res.val=MD-val; } else{ res.val=0; } return res; } inline operator bool(void){ return val!=0; } inline operator int(void){ return get(); } inline operator long long(void){ return get(); } inline Modint inverse(){ int a = val; int b = MD; int u = 1; int v = 0; int t; Modint res; while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if(u < 0){ u += MD; } res.val = u; return res; } inline Modint pw(unsigned long long b){ Modint a(*this); Modint res; res.val = 1; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } inline bool operator==(int a){ return ord(a)==val; } inline bool operator!=(int a){ return ord(a)!=val; } } ; inline Modint operator+(int a, Modint b){ return Modint(a)+=b; } inline Modint operator-(int a, Modint b){ return Modint(a)-=b; } inline Modint operator*(int a, Modint b){ return Modint(a)*=b; } inline Modint operator/(int a, Modint b){ return Modint(a)/=b; } inline Modint operator+(long long a, Modint b){ return Modint(a)+=b; } inline Modint operator-(long long a, Modint b){ return Modint(a)-=b; } inline Modint operator*(long long a, Modint b){ return Modint(a)*=b; } inline Modint operator/(long long a, Modint b){ return Modint(a)/=b; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(char &c){ int i; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(unsigned x){ int s=0; char f[10]; while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(unsigned long long x){ int s=0; char f[21]; while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(Modint x){ int i; i = (int)x; wt_L(i); } int WRITER_DOUBLE_DIGIT = 15; inline int writerDigit_double(){ return WRITER_DOUBLE_DIGIT; } inline void writerDigit_double(int d){ WRITER_DOUBLE_DIGIT = d; } inline void wt_L(double x){ const int d = WRITER_DOUBLE_DIGIT; int k; int r; double v; if(x!=x || (x==x+1 && x==2*x)){ my_putchar_unlocked('E'); my_putchar_unlocked('r'); my_putchar_unlocked('r'); return; } if(x < 0){ my_putchar_unlocked('-'); x = -x; } x += 0.5 * pow(0.1, d); r = 0; v = 1; while(x >= 10*v){ v *= 10; r++; } while(r >= 0){ r--; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; v *= 0.1; my_putchar_unlocked(k + '0'); } if(d > 0){ my_putchar_unlocked('.'); v = 1; for(r=(0);r<(d);r++){ v *= 0.1; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; my_putchar_unlocked(k + '0'); } } } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } inline void wt_L(string &x){ int i=0; for(i=0;x[i]!='\0';i++){ my_putchar_unlocked(x[i]); } } template<class T> int runLength(int N, T *arr, void *val_s = NULL, void *len_s = NULL){ int i; int rN; T*val = (T*) val_s; int*len = (int*) len_s; if(N==0){ return 0; } if(val==NULL || len==NULL){ void*mem = wmem; if(val==NULL){ walloc1d(&val, N, &mem); } if(len==NULL){ walloc1d(&len, N, &mem); } } rN = 1; val[0] = arr[0]; len[0] = 1; for(i=(1);i<(N);i++){ if(val[rN-1] == arr[i]){ len[rN-1]++; } else{ val[rN] = arr[i]; len[rN] = 1; rN++; } } return rN; } template<class T> struct Arr1d{ int n; int mem; T*d; T& operator[](int a){ return d[a]; } void sort(){ reset(); std::sort(d, d+n); } int set_nextGT; int nextGT_mem; int*nextGT; void setNextGT(void *mem = wmem){ int i; int s = 0; int*st; set_nextGT = 1; if(nextGT_mem < n){ delete[] nextGT; nextGT = new int[n]; nextGT_mem = n; } walloc1d(&st, n, &mem); for(i=(n)-1;i>=(0);i--){ while(s && d[st[s-1]] <= d[i]){ s--; } if(s==0){ nextGT[i] = n; } else{ nextGT[i] = st[s-1]; } st[s++] = i; } } int NextGT(int i){ if(set_nextGT==0){ setNextGT(); } return nextGT[i]; } void reset(){ set_nextGT = 0; } void constructor(){ n = mem = 0; d = NULL; set_nextGT = 0; nextGT_mem = 0; nextGT = NULL; } void destructor(){ delete[] d; d = NULL; mem = n = 0; set_nextGT = 0; nextGT_mem = 0; delete[] nextGT; nextGT = NULL; } void constructor(int nn){ constructor(); malloc(nn); } void memory_expand(int nn){ if(mem < nn){ delete[] d; d = new T[nn]; mem = nn; } } void malloc(int nn){ reset(); memory_expand(nn); n = nn; } void setN(int nn){ reset(); memory_expand(nn); n = nn; } void setN(int nn, T val){ int i; reset(); memory_expand(nn); n = nn; for(i=(0);i<(n);i++){ d[i] = val; } } void set(vector<T> &a){ int i; int nn = a.size(); setN(nn); for(i=(0);i<(nn);i++){ d[i] = a[i]; } } void set(int nn, T a[]){ int i; setN(nn); for(i=(0);i<(nn);i++){ d[i] = a[i]; } } void free(){ destructor(); } Arr1d(){ constructor(); } Arr1d(int nn){ constructor(nn); } ~Arr1d(){ destructor(); } } ; int N; char S[3000000+2]; int nx0[3000000+2]; int nx1[3000000+2]; Modint dp[3000000+2]; int sz; int len[3000000+2]; int st[3000000+2]; char v[3000000+2]; Arr1d<int> arr; int main(){ wmem = memarr; int i; int j; int k; int lz = 0; Modint res = 0; N = rd(S); sz = runLength(N,S,v,len); for(i=(0);i<(sz);i++){ if(v[i] == '1'){ len[i] *= -1; } } arr.set(sz,len); if(sz==1){ wt_L(abs(len[0])); wt_L('\n'); return 0; } if(v[sz-1]=='0'){ lz = len[sz-1]; } for(i=(0);i<(N+1);i++){ nx0[i] = nx1[i] = -1; } for(i=(0);i<(N);i++){ if(S[i]=='0'){ nx0[i] = i+1; } } k = -1; for(i=(N)-1;i>=(0);i--){ if(S[i]=='1'){ k = i+1; } nx1[i] = k; } k = -1; for(i=(N)-1;i>=(0);i--){ if(S[i]=='0'){ k = i+1; } if(S[i]=='1'){ nx0[i+1] = k; } } for(i=(0);i<(sz);i++){ st[i+1] = st[i] + abs(len[i]); } for(i=(0);i<(sz);i++){ if(i && v[i]=='0'){ j = arr.NextGT(i); if(j < sz){ nx0[st[i+1]] = st[j] + len[i]+1; } } } dp[0] = 1; for(i=(0);i<(N);i++){ if(nx0[i] != -1){ dp[nx0[i]] += dp[i]; } if(nx1[i] != -1){ dp[nx1[i]] += dp[i]; } } k = 1073709056; for(i=(0);i<(N);i++){ if(S[i]=='1'){ k = 0; } else{ k++; } if(k <= lz){ res += dp[i+1]; } } wt_L(res); wt_L('\n'); return 0; } // cLay version 20210819-1 [beta] // --- original code --- // #define MD 924844033 // int N; // char S[3d6+2]; // int nx0[], nx1[]; // Modint dp[]; // int sz, len[], st[]; char v[]; // Arr1d<int> arr; // // { // int i, j, k, lz = 0; // Modint res = 0; // rd(S@N); // // sz = runLength(N,S,v,len); // rep(i,sz) if(v[i] == '1') len[i] *= -1; // arr.set(sz,len); // // if(sz==1) wt(abs(len[0])), return 0; // // if(v[sz-1]=='0') lz = len[sz-1]; // // rep(i,N+1) nx0[i] = nx1[i] = -1; // // rep(i,N) if(S[i]=='0') nx0[i] = i+1; // // k = -1; // rrep(i,N){ // if(S[i]=='1') k = i+1; // nx1[i] = k; // } // // k = -1; // rrep(i,N){ // if(S[i]=='0') k = i+1; // if(S[i]=='1') nx0[i+1] = k; // } // // rep(i,sz) st[i+1] = st[i] + abs(len[i]); // rep(i,sz) if(i && v[i]=='0'){ // j = arr.NextGT(i); // if(j < sz) nx0[st[i+1]] = st[j] + len[i]+1; // } // // dp[0] = 1; // rep(i,N){ // // wt(S[i],":",i,dp[i],":",nx0[i],nx1[i]); // if(nx0[i] != -1) dp[nx0[i]] += dp[i]; // if(nx1[i] != -1) dp[nx1[i]] += dp[i]; // } // // wt(dp[N]); // // k = int_inf; // rep(i,N){ // if(S[i]=='1') k = 0; else k++; // if(k <= lz) res += dp[i+1]; // } // wt(res); // }