結果

問題 No.2039 Copy and Avoid
ユーザー SSRSSSRS
提出日時 2022-08-12 21:46:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 176,012 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 09:14:07
合計ジャッジ時間 3,617 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 35 ms
4,348 KB
testcase_14 AC 36 ms
4,348 KB
testcase_15 AC 35 ms
4,348 KB
testcase_16 AC 34 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 6 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1100000000000000000;
int main(){
  int N, M, A, B;
  cin >> N >> M >> A >> B;
  vector<int> C(M);
  for (int i = 0; i < M; i++){
    cin >> C[i];
  }
  vector<int> F;
  for (int i = 1; i * i <= N; i++){
    if (N % i == 0){
      F.push_back(i);
      if (i * i < N){
        F.push_back(N / i);
      }
    }
  }
  sort(F.begin(), F.end());
  int cnt = F.size();
  vector<int> mn(cnt, N + 1);
  for (int i = 0; i < cnt; i++){
    for (int j = 0; j < M; j++){
      if (C[j] % F[i] == 0){
        mn[i] = min(mn[i], C[j]);
      }
    }
  }
  vector<long long> dp(cnt, INF);
  dp[0] = 0;
  for (int i = 0; i < cnt; i++){
    for (int j = i + 1; j < cnt; j++){
      if (F[j] % F[i] == 0 && F[j] < mn[i]){
        dp[j] = min(dp[j], dp[i] + (long long) (F[j] / F[i] - 1) * A + B);
      }
    }
  }
  if (dp[cnt - 1] == INF){
    cout << -1 << endl;
  } else {
    cout << dp[cnt - 1] - B << endl;
  }
}
0