結果
| 問題 |
No.695 square1001 and Permutation 4
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2018-12-19 11:34:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,739 ms / 7,000 ms |
| コード長 | 1,600 bytes |
| コンパイル時間 | 1,112 ms |
| コンパイル使用メモリ | 87,588 KB |
| 実行使用メモリ | 42,588 KB |
| 最終ジャッジ日時 | 2024-07-22 19:35:42 |
| 合計ジャッジ時間 | 12,210 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 |
ソースコード
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int mid=10000000;
int MOD[3]={17, 9920467, 592951213};
int dp[mid];
vector<int> x1, x2;
int n, m;
ll solve(int mod){
fill(dp, dp+min(mid, n), 0);
dp[0]=1;
for(int i=1; i<min(mid, n); i++){
for(auto x:x1){
if(i-x>=0) dp[i]=(dp[i]+dp[i-x])%mod;
}
}
if(n<=mid) return (ll)dp[n-1];
ll ans=0;
for(auto x:x2){
for(int i=0; i<n-x; i++){
ll c1=dp[i], c2=dp[n-1-i-x];
ans+=(c1*c2);
ans%=mod;
}
}
for(int i=0; i<n-mid; i++){
int c=0;
for(auto x:x1){
c+=dp[(i+mid-x)%mid];
c%=mod;
}
dp[i]=c;
}
ans+=dp[n-1-mid];
ans%=mod;
return ans;
}
ll extgcd(ll a, ll b, ll& x, ll& y){
ll d=a;
if(b!=0){
d=extgcd(b, a%b, y, x);
y-=(a/b)*x;
}else{
x=1, y=0;
}
return d;
}
ll inv(ll a, ll p){
ll x, y;
extgcd(a, p, x, y);
if(x<0){
return p-(-x%p);
}else{
return x%p;
}
}
int main()
{
cin>>n>>m;
for(int i=0; i<m; i++){
int x;cin>>x;
if(x<mid) x1.push_back(x);
else x2.push_back(x);
}
ll ans[3];
for(int i=0; i<3; i++) ans[i]=solve(MOD[i]);
ll a[3]; a[0]=ans[0];
a[1]=(ans[1]+MOD[1]-a[0])*inv(MOD[0], MOD[1])%MOD[1];
a[2]=(ans[2]-(a[1]*MOD[0]+a[0])%MOD[2]+MOD[2])*inv(MOD[0]*MOD[1]%MOD[2], MOD[2])%MOD[2];
cout<<a[0]+a[1]*MOD[0]+a[2]*MOD[0]*MOD[1]<<endl;
return 0;
}
chocorusk