結果

問題 No.695 square1001 and Permutation 4
ユーザー maspymaspy
提出日時 2020-05-14 22:11:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,070 ms / 7,000 ms
コード長 1,205 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 68,560 KB
実行使用メモリ 42,688 KB
最終ジャッジ日時 2023-09-30 01:41:34
合計ジャッジ時間 9,133 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 195 ms
42,400 KB
testcase_01 AC 648 ms
42,588 KB
testcase_02 AC 72 ms
42,436 KB
testcase_03 AC 71 ms
42,436 KB
testcase_04 AC 616 ms
42,508 KB
testcase_05 AC 587 ms
42,688 KB
testcase_06 AC 496 ms
42,432 KB
testcase_07 AC 645 ms
42,440 KB
testcase_08 AC 487 ms
42,424 KB
testcase_09 AC 442 ms
42,448 KB
testcase_10 AC 579 ms
42,648 KB
testcase_11 AC 1,070 ms
42,484 KB
testcase_12 AC 849 ms
42,456 KB
testcase_13 AC 782 ms
42,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
            }
            if(i + x > n){
                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;
}
0