結果
問題 | No.1621 Sequence Inversions |
ユーザー | publfl |
提出日時 | 2021-07-22 22:43:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 168 ms / 3,000 ms |
コード長 | 1,508 bytes |
コンパイル時間 | 656 ms |
コンパイル使用メモリ | 67,416 KB |
実行使用メモリ | 228,976 KB |
最終ジャッジ日時 | 2023-09-24 18:15:17 |
合計ジャッジ時間 | 4,092 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
15,388 KB |
testcase_01 | AC | 3 ms
11,288 KB |
testcase_02 | AC | 15 ms
52,252 KB |
testcase_03 | AC | 21 ms
76,836 KB |
testcase_04 | AC | 62 ms
207,776 KB |
testcase_05 | AC | 3 ms
11,284 KB |
testcase_06 | AC | 11 ms
46,136 KB |
testcase_07 | AC | 22 ms
82,980 KB |
testcase_08 | AC | 149 ms
222,816 KB |
testcase_09 | AC | 165 ms
220,748 KB |
testcase_10 | AC | 168 ms
220,768 KB |
testcase_11 | AC | 151 ms
222,752 KB |
testcase_12 | AC | 153 ms
222,812 KB |
testcase_13 | AC | 163 ms
222,832 KB |
testcase_14 | AC | 87 ms
224,800 KB |
testcase_15 | AC | 81 ms
228,976 KB |
testcase_16 | AC | 106 ms
211,796 KB |
testcase_17 | AC | 146 ms
226,804 KB |
testcase_18 | AC | 101 ms
209,572 KB |
testcase_19 | AC | 16 ms
60,388 KB |
testcase_20 | AC | 60 ms
155,896 KB |
testcase_21 | AC | 158 ms
228,956 KB |
testcase_22 | AC | 92 ms
228,900 KB |
testcase_23 | AC | 166 ms
228,900 KB |
testcase_24 | AC | 6 ms
23,588 KB |
testcase_25 | AC | 7 ms
27,604 KB |
testcase_26 | AC | 4 ms
11,300 KB |
testcase_27 | AC | 3 ms
13,304 KB |
testcase_28 | AC | 3 ms
13,340 KB |
ソースコード
#include <stdio.h> #include <algorithm> #include <vector> #include <map> #define MOD 998244353 long long int check[110][10010], check2[110][2510][110]; long long int func2(int k, int s, int t) { if(s<0) return 0; if(t<0) return 0; if(k==0) { if(s==0) return 1; else return 0; } if(check2[k][s][t]!=-1) return check2[k][s][t]; long long int s1 = func2(k,s,t-1); long long int s2 = func2(k-1,s-t,t); return check2[k][s][t] = (s1+s2)%MOD; } int b,c; int sum[110],count[110]; long long int func(int k, int C) { if(C>b) return 0; if(k>c) { if(C==b) return 1; else return 0; } if(check[k][C]!=-1) return check[k][C]; int N = sum[k-1]; //0 ~ N long long int ans = 0; for(int i=0;i<=count[k]*N;i++) { long long int t = func(k+1,C+i) * func2(count[k],i,N); t %= MOD, ans += t, ans %= MOD; } return check[k][C] = ans; } std::vector<int> index; std::map<int,int> hash; int x[110]; int main() { int a; scanf("%d%d",&a,&b); for(int i=1;i<=a;i++) scanf("%d",&x[i]); for(int i=1;i<=a;i++) index.push_back(x[i]); std::sort(index.begin(),index.end()); index.erase(std::unique(index.begin(),index.end()),index.end()); for(int i=0;i<index.size();i++) hash[index[i]] = i+1; c = index.size(); for(int i=1;i<=a;i++) count[hash[x[i]]]++; for(int i=1;i<=c;i++) sum[i] = sum[i-1] + count[i]; for(int i=1;i<=c;i++) for(int j=0;j<=b;j++) check[i][j] = -1; for(int i=1;i<=a;i++) for(int j=0;j<=2500;j++) for(int k=0;k<=a;k++) check2[i][j][k] = -1; printf("%lld",func(1,0)); }