結果

問題 No.1731 Product of Subsequence
ユーザー tonyu0tonyu0
提出日時 2021-11-06 00:04:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 666 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 123,840 KB
実行使用メモリ 122,780 KB
最終ジャッジ日時 2023-08-07 23:25:24
合計ジャッジ時間 8,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 565 ms
116,024 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 20 ms
6,724 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 657 ms
122,472 KB
testcase_11 AC 575 ms
110,992 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 14 ms
6,428 KB
testcase_14 AC 495 ms
83,200 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 447 ms
95,900 KB
testcase_19 AC 13 ms
6,400 KB
testcase_20 AC 360 ms
72,736 KB
testcase_21 AC 666 ms
122,780 KB
testcase_22 AC 3 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 18 ms
6,140 KB
testcase_25 AC 7 ms
4,456 KB
testcase_26 AC 110 ms
21,732 KB
testcase_27 AC 159 ms
30,568 KB
testcase_28 AC 313 ms
58,144 KB
testcase_29 AC 131 ms
22,880 KB
testcase_30 AC 535 ms
121,844 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 49 ms
11,768 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