結果
問題 | No.1654 Binary Compression |
ユーザー | LayCurse |
提出日時 | 2021-08-20 22:12:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 10,879 bytes |
コンパイル時間 | 2,811 ms |
コンパイル使用メモリ | 224,608 KB |
実行使用メモリ | 92,160 KB |
最終ジャッジ日時 | 2024-10-14 03:59:15 |
合計ジャッジ時間 | 9,616 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
15,232 KB |
testcase_01 | AC | 15 ms
15,104 KB |
testcase_02 | AC | 16 ms
15,232 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 115 ms
92,160 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 66 ms
42,496 KB |
testcase_42 | AC | 64 ms
42,496 KB |
testcase_43 | AC | 65 ms
42,496 KB |
testcase_44 | WA | - |
testcase_45 | AC | 67 ms
42,624 KB |
testcase_46 | AC | 66 ms
42,496 KB |
testcase_47 | AC | 14 ms
15,104 KB |
testcase_48 | AC | 14 ms
15,104 KB |
testcase_49 | WA | - |
testcase_50 | AC | 108 ms
87,168 KB |
testcase_51 | WA | - |
testcase_52 | WA | - |
ソースコード
#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(Modint x){ int i; i = (int)x; wt_L(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(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; } for(i=(0);i<(sz);i++){ st[i+1] = st[i] + abs(len[i]); } for(i=(0);i<(sz);i++){ if(v[i]=='0'){ j = arr.NextGT(i); if(j < sz){ nx0[st[i+1]-1] = st[j] + len[i]; } } } 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 = 0; 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(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; // } // // rep(i,sz) st[i+1] = st[i] + abs(len[i]); // rep(i,sz) if(v[i]=='0'){ // j = arr.NextGT(i); // if(j < sz) nx0[st[i+1]-1] = st[j] + len[i]; // } // // dp[0] = 1; // rep(i,N){ // if(nx0[i] != -1) dp[nx0[i]] += dp[i]; // if(nx1[i] != -1) dp[nx1[i]] += dp[i]; // } // // k = 0; // rep(i,N){ // if(S[i]=='1') k = 0; else k++; // if(k <= lz) res += dp[i+1]; // } // wt(res); // }