結果

問題 No.2039 Copy and Avoid
ユーザー olpheolphe
提出日時 2022-08-12 22:36:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,645 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 141,904 KB
実行使用メモリ 24,572 KB
最終ジャッジ日時 2023-10-24 10:53:35
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
24,572 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 4 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 1 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 95 ms
24,572 KB
testcase_14 AC 95 ms
24,572 KB
testcase_15 AC 99 ms
24,572 KB
testcase_16 AC 91 ms
22,460 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 8 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 "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> M >> L >> R;
	vector<int>v(M);
	for (auto& i : v)cin >> i;
	vector<int>d;
	for (int i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			d.push_back(i);
			d.push_back(N / i);
		}
	}
	sort(d.begin(), d.end());
	vector<vector<int>>ng(d.size(), vector<int>(d.size()));
	for (int i = 0; i < d.size(); i++) {
		for (auto j : v) {
			if (j % d[i] == 0) {
				for (int k = 0; k < d.size(); k++) {
					if (j <= d[k]) {
						ng[k][i] = true;
					}
				}
			}
		}
	}
	vector<vector<long long>>dp(d.size(), vector<long long>(d.size(), 1LL << 60));
	dp[0][0] = 0;
	for (int i = 1; i < d.size(); i++) {
		bool con = false;
		for (auto j : v)if (d[i] == j)con = true;
		if (con)continue;
		for (int j = 0; j < i; j++) {
			if (d[i] % d[j])continue;
			if (ng[i][j])continue;
			dp[i][j] = dp[j][j] + L * (d[i] / d[j]-1);
			dp[i][i] = min(dp[i][i], dp[i][j] + R);
		}
	}
	long long ans = 1LL << 60;
	for (auto i : dp.back()) {
		ans = min(ans, i);
	}
	if (ans == 1LL << 60)ans = -1;
	cout << ans << endl;
}
0