結果
| 問題 |
No.695 square1001 and Permutation 4
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-05-14 22:08:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,138 bytes |
| コンパイル時間 | 1,409 ms |
| コンパイル使用メモリ | 66,048 KB |
| 最終ジャッジ日時 | 2025-01-10 10:55:19 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 WA * 1 RE * 1 |
ソースコード
#include<iostream>
using namespace std;
#define U 10000010
int dp[U];
int X[5];
int n, m;
using ll = long long;
ll solve(ll mod){
for(int i=0;i<U;i++){
dp[i] = 0;
}
dp[0] = 1;
for(int i=1;i<U;i++){
for(int j=0;j<m;j++){
int x = X[j];
if(x <= i){
dp[i] += dp[i-x];
}
if(dp[i] >= mod){
dp[i] -= mod;
}
}
}
if (n < U){
return dp[n];
}
ll ret = 0;
for(int i=0;i<U;i++){
for(int j=0;j<m;j++){
int x = X[j];
if(i + x < U){
continue;
}
int r = n - i - x;
ret += (ll)(dp[i]) * (ll)(dp[r]) % mod;
}
}
return ret % mod;
}
int main(){
cin >> n >> m;
n--;
for(int i=0;i<m;i++){
cin >> X[i];
}
ll mod1 = 168647939;
ll mod2 = 592951213;
ll mod = mod1 * mod2;
ll x1 = solve(mod1);
ll x2 = solve(mod2);
ll d = (x2 - x1) * 442445312LL % mod2;
ll x = x1 + d * mod1;
if(x<0){
x += mod;
}
cout << x << endl;
return 0;
}
maspy