結果
問題 | No.1621 Sequence Inversions |
ユーザー | LayCurse |
提出日時 | 2021-07-22 21:46:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,793 ms / 3,000 ms |
コード長 | 9,277 bytes |
コンパイル時間 | 2,921 ms |
コンパイル使用メモリ | 225,040 KB |
実行使用メモリ | 202,880 KB |
最終ジャッジ日時 | 2024-07-17 17:12:42 |
合計ジャッジ時間 | 29,150 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
202,752 KB |
testcase_01 | AC | 131 ms
202,624 KB |
testcase_02 | AC | 131 ms
202,752 KB |
testcase_03 | AC | 131 ms
202,752 KB |
testcase_04 | AC | 1,053 ms
202,624 KB |
testcase_05 | AC | 132 ms
202,752 KB |
testcase_06 | AC | 132 ms
202,752 KB |
testcase_07 | AC | 135 ms
202,752 KB |
testcase_08 | AC | 1,264 ms
202,880 KB |
testcase_09 | AC | 1,586 ms
202,880 KB |
testcase_10 | AC | 2,756 ms
202,880 KB |
testcase_11 | AC | 1,360 ms
202,752 KB |
testcase_12 | AC | 2,749 ms
202,624 KB |
testcase_13 | AC | 2,793 ms
202,752 KB |
testcase_14 | AC | 532 ms
202,752 KB |
testcase_15 | AC | 338 ms
202,624 KB |
testcase_16 | AC | 901 ms
202,752 KB |
testcase_17 | AC | 1,786 ms
202,880 KB |
testcase_18 | AC | 725 ms
202,624 KB |
testcase_19 | AC | 130 ms
202,752 KB |
testcase_20 | AC | 250 ms
202,752 KB |
testcase_21 | AC | 2,064 ms
202,752 KB |
testcase_22 | AC | 651 ms
202,752 KB |
testcase_23 | AC | 2,428 ms
202,752 KB |
testcase_24 | AC | 131 ms
202,752 KB |
testcase_25 | AC | 131 ms
202,880 KB |
testcase_26 | AC | 130 ms
202,752 KB |
testcase_27 | AC | 130 ms
202,752 KB |
testcase_28 | AC | 129 ms
202,752 KB |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #include<bits/stdc++.h> using namespace std; #define MD (998244353U) template<class T> struct cLtraits_identity{ using type = T; } ; template<class T> using cLtraits_try_make_signed = typename conditional< is_integral<T>::value, make_signed<T>, cLtraits_identity<T> >::type; template <class S, class T> struct cLtraits_common_type{ using tS = typename cLtraits_try_make_signed<S>::type; using tT = typename cLtraits_try_make_signed<T>::type; using type = typename common_type<tS,tT>::type; } ; void*wmem; char memarr[96000000]; template<class S, class T> inline auto min_L(S a, T b) -> typename cLtraits_common_type<S,T>::type{ return (typename cLtraits_common_type<S,T>::type) a <= (typename cLtraits_common_type<S,T>::type) b ? a : b; } 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; } template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){ sort(a, a+N); } 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(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } 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; } int N; int K; int A[100]; int sz; int arr[100]; Modint dp[5000]; Modint nx[5000]; Modint dp2[101][101][5000]; int main(){ int V9aVTaxx; wmem = memarr; int i; int j; int k; int x = 0; int y; rd(N); rd(K); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } sortA_L(N,A); sz = runLength(N,A,NULL,arr); for(i=(0);i<(N+1);i++){ dp2[i][0][0] = 1; } for(i=(0);i<(N+1);i++){ for(j=(1);j<(N+1);j++){ if(i+j <= N){ for(k=(0);k<(K+1);k++){ int m; int tU__gIr_ = min_L(k, i)+1; for(m=(0);m<(tU__gIr_);m++){ dp2[i][j][k] += dp2[m][j-1][k-m]; } } } } } dp[0] = 1; for(V9aVTaxx=(0);V9aVTaxx<(sz);V9aVTaxx++){ auto&y = arr[V9aVTaxx]; for(i=(0);i<(K+1);i++){ nx[i] = 0; } for(i=(0);i<(K+1);i++){ if(dp[i]){ for(j=(0);j<(K+1-i);j++){ if(dp2[x][y][j]){ nx[i+j] += dp[i] * dp2[x][y][j]; } } } } for(i=(0);i<(K+1);i++){ dp[i] = nx[i]; } x += y; } wt_L(dp[K]); wt_L('\n'); return 0; } // cLay version 20210717-1 [beta] // --- original code --- // #define MD 998244353 // int N, K, A[100]; // int sz, arr[100]; // Modint dp[5000], nx[5000], dp2[101][101][5000]; // { // int i, j, k, x = 0, y; // rd(N,K,A(N)); // // N = 100; rep(i,N) A[i] = rand()%100; // sortA(N,A); // sz = runLength(N,A,NULL,arr); // // rep(i,N+1) dp2[i][0][0] = 1; // rep(i,N+1) rep(j,1,N+1) if(i+j <= N) rep(k,K+1){ // REP(m,min(k,i)+1) dp2[i][j][k] += dp2[m][j-1][k-m]; // // if(dp2[i][j][k]) wt(i,j,k,":",dp2[i][j][k]); // } // // dp[0] = 1; // rep[arr](y,sz){ // rep(i,K+1) nx[i] = 0; // rep(i,K+1) if(dp[i]) rep(j,K+1-i) if(dp2[x][y][j]) nx[i+j] += dp[i] * dp2[x][y][j]; // rep(i,K+1) dp[i] = nx[i]; // // wt(x,y,":",dp(10)); // x += y; // } // wt(dp[K]); // }