結果

問題 No.1731 Product of Subsequence
ユーザー tonyu0tonyu0
提出日時 2021-11-06 00:04:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 640 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 1,261 ms
コンパイル使用メモリ 123,088 KB
実行使用メモリ 122,752 KB
最終ジャッジ日時 2024-04-25 17:36:57
合計ジャッジ時間 7,732 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 553 ms
116,224 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 20 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 632 ms
122,624 KB
testcase_11 AC 559 ms
110,848 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 13 ms
6,940 KB
testcase_14 AC 478 ms
83,072 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 432 ms
96,000 KB
testcase_19 AC 13 ms
6,940 KB
testcase_20 AC 351 ms
72,832 KB
testcase_21 AC 640 ms
122,752 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 17 ms
6,944 KB
testcase_25 AC 7 ms
6,940 KB
testcase_26 AC 105 ms
21,888 KB
testcase_27 AC 154 ms
30,848 KB
testcase_28 AC 302 ms
58,240 KB
testcase_29 AC 127 ms
22,784 KB
testcase_30 AC 525 ms
122,112 KB
testcase_31 AC 3 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 3 ms
6,940 KB
testcase_34 AC 48 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)

constexpr int MOD = 1000000007;

unordered_map<ll, ll> dp[2002];
// dp[i][j] := i番目まで選んで、あまりj

int main() {
  cin.tie(0)->sync_with_stdio(0);
  ll n, k;
  cin >> n >> k;
  if(k==1){
      ll ii = 1;
      rep(i,0,n)(ii*=2)%=MOD;
      cout<<ii-1;
      return 0;
  }
  vector<ll> a(n);
  rep(i, 0, n){cin>>a[i];a[i]%=k;}
  dp[0][1] = 1;
  rep(i, 0, n) {
    for (auto &[j, v] : dp[i]) {
      (dp[i + 1][gcd(j * a[i], k)] += v)%=MOD;
      (dp[i + 1][j] += v)%=MOD;
    }
  }
  cout << dp[n][k];

  return 0;
}
0