結果

問題 No.695 square1001 and Permutation 4
ユーザー maspymaspy
提出日時 2020-05-14 22:06:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,139 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 70,164 KB
実行使用メモリ 42,484 KB
最終ジャッジ日時 2023-09-30 01:41:59
合計ジャッジ時間 8,576 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 189 ms
42,352 KB
testcase_01 AC 595 ms
42,404 KB
testcase_02 AC 71 ms
42,384 KB
testcase_03 AC 70 ms
42,432 KB
testcase_04 AC 559 ms
42,380 KB
testcase_05 AC 545 ms
42,380 KB
testcase_06 AC 456 ms
42,420 KB
testcase_07 AC 599 ms
42,388 KB
testcase_08 AC 468 ms
42,368 KB
testcase_09 AC 413 ms
42,484 KB
testcase_10 AC 539 ms
42,384 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 AC 788 ms
42,448 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(int 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;
}
0