結果
問題 | No.695 square1001 and Permutation 4 |
ユーザー | ciel |
提出日時 | 2018-06-10 23:32:08 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,241 ms / 7,000 ms |
コード長 | 744 bytes |
コンパイル時間 | 1,797 ms |
コンパイル使用メモリ | 83,512 KB |
実行使用メモリ | 41,776 KB |
最終ジャッジ日時 | 2023-09-30 01:36:55 |
合計ジャッジ時間 | 6,910 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 34 ms
5,000 KB |
testcase_02 | AC | 70 ms
12,864 KB |
testcase_03 | AC | 36 ms
12,880 KB |
testcase_04 | AC | 174 ms
12,800 KB |
testcase_05 | AC | 305 ms
12,892 KB |
testcase_06 | AC | 617 ms
22,628 KB |
testcase_07 | AC | 309 ms
22,616 KB |
testcase_08 | AC | 420 ms
22,532 KB |
testcase_09 | AC | 754 ms
22,636 KB |
testcase_10 | AC | 127 ms
6,940 KB |
testcase_11 | AC | 1,241 ms
41,676 KB |
testcase_12 | AC | 934 ms
41,776 KB |
testcase_13 | AC | 675 ms
41,672 KB |
ソースコード
#include <vector> #include <algorithm> #include <cstdio> using namespace std; int solve(int n,int M,const vector<int> &x){ int m=n/2,r=0; vector<int> v(n-m);v[0]=1; for(int i=1;i<n-m;i++)for(auto &e:x){ if(e<=i)v[i]=(v[i]+v[i-e])%M; } for(auto &e:x)for(int i=0;i<m;i++){ if(m<=i+e && i+e<n){ r=(r+1LL*v[i]*v[n-i-e-1])%M; } } return r; } long long pow(long long x,long long y,long long mod){ long long z=1; for(;y;y>>=1){ if(y&1)z=z*x%mod; x=x*x%mod; } return z; } int main(){ int n,m; scanf("%d%d",&n,&m); vector<int>x(m); for(int i=0;i<m;i++)scanf("%d",&x[i]); int M1=168647939,M2=592951213; int R1=solve(n,M1,x),R2=solve(n,M2,x); long long Rm=(R2-R1+M2)*pow(M1,M2-2,M2)%M2; printf("%lld\n",1LL*Rm*M1+R1); }