結果

問題 No.1731 Product of Subsequence
ユーザー SSRSSSRS
提出日時 2021-11-05 21:32:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 174,812 KB
実行使用メモリ 24,448 KB
最終ジャッジ日時 2024-04-24 05:19:45
合計ジャッジ時間 5,625 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
23,296 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 289 ms
24,320 KB
testcase_11 AC 240 ms
21,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 238 ms
19,328 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 313 ms
24,320 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 242 ms
20,224 KB
testcase_21 AC 297 ms
24,320 KB
testcase_22 AC 87 ms
24,448 KB
testcase_23 WA -
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 43 ms
7,424 KB
testcase_27 AC 64 ms
8,704 KB
testcase_28 AC 140 ms
13,312 KB
testcase_29 AC 48 ms
7,680 KB
testcase_30 AC 184 ms
24,320 KB
testcase_31 AC 81 ms
24,320 KB
testcase_32 WA -
testcase_33 AC 8 ms
5,376 KB
testcase_34 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long gcd(long long x, long long y){
  if (y == 0){
    return x;
  } else {
    return gcd(y, x % y);
  }
}
int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i] = gcd(A[i], K);
  }
  vector<int> f;
  for (int i = 1; i * i <= K; i++){
    if (K % i == 0){
      f.push_back(i);
      if (i * i < K){
        f.push_back(K / i);
      }
    }
  }
  sort(f.begin(), f.end());
  int M = f.size();
  vector<vector<long long>> dp(N + 1, vector<long long>(M, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;
      long long p = gcd(f[j] * A[i], K);
      int j2 = lower_bound(f.begin(), f.end(), p) - f.begin();
      dp[i + 1][j2] += dp[i][j];
      dp[i + 1][j2] %= MOD;
    }
  }
  cout << dp[N][M - 1] << endl;
}
0