답안 #696423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696423 2023-02-06T13:04:59 Z SanguineChameleon Gauss (COCI17_gauss) C++17
0 / 160
2000 ms 95480 KB
// BEGIN BOILERPLATE CODE

#include <bits/stdc++.h>
using namespace std;

#ifdef KAMIRULEZ
	const bool kami_loc = true;
	const long long kami_seed = 69420;
#else
	const bool kami_loc = false;
	const long long kami_seed = chrono::steady_clock::now().time_since_epoch().count();
#endif

const string kami_fi = "kamirulez.inp";
const string kami_fo = "kamirulez.out";
mt19937_64 kami_gen(kami_seed);

long long rand_range(long long rmin, long long rmax) {
	uniform_int_distribution<long long> rdist(rmin, rmax);
	return rdist(kami_gen);
}

long double rand_real(long double rmin, long double rmax) {
	uniform_real_distribution<long double> rdist(rmin, rmax);
	return rdist(kami_gen);
}

void file_io(string fi, string fo) {
	if (fi != "" && (!kami_loc || fi == kami_fi)) {
		freopen(fi.c_str(), "r", stdin);
	}
	if (fo != "" && (!kami_loc || fo == kami_fo)) {
		freopen(fo.c_str(), "w", stdout);
	}
}

void set_up() {
	if (kami_loc) {
		file_io(kami_fi, kami_fo);
	}
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void just_do_it();

void just_exec_it() {
	if (kami_loc) {
		auto pstart = chrono::steady_clock::now();
		just_do_it();
		auto pend = chrono::steady_clock::now();
		long long ptime = chrono::duration_cast<chrono::milliseconds>(pend - pstart).count();
		string bar(50, '=');
		cout << '\n' << bar << '\n';
		cout << "Time: " << ptime << " ms" << '\n';
	}
	else {
		just_do_it();
	}
}

int main() {
	set_up();
	just_exec_it();
	return 0;
}

// END BOILERPLATE CODE

// BEGIN MAIN CODE

const int inf = 1e9 + 20;
const int lim = 1e6;
int F[10020];
int L[1020];
int X[52];
int C[52];
int dp[lim + 20][22];
int Dc[lim + 20];
int Pc[lim + 20];
int best1[22];
int best2[22];
int best3[52];

void just_do_it() {
	fill_n(&dp[0][0], (lim + 20) * 22, inf);
	int K;
	cin >> K;
	for (int i = 1; i <= K; i++) {
		cin >> F[i];
	}
	int M;
	cin >> M;
	for (int i = 1; i <= M; i++) {
		cin >> L[i];
	}
	int T;
	cin >> T;
	for (int i = 1; i <= T; i++) {
		cin >> X[i] >> C[i];
	}
	for (int i = 1; i <= lim; i++) {
		for (int j = i; j <= lim; j += i) {
			Dc[j]++;
			if (Dc[i] == 2) {
				int tmp = j;
				do {
					Pc[j]++;
					tmp /= i;
				}
				while (tmp % i == 0);
			}
		}
	}
	dp[1][0] = 0;
	for (int i = 1; i <= lim; i++) {
		for (int j = i, d = 1; j <= lim; j += i, d++) {
			for (int k = 0; k <= Pc[i]; k++) {
				dp[j][k + 1] = min(dp[j][k + 1], dp[i][k] + (Dc[d] <= K ? F[Dc[d]] : 0));
			}
		}
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int A, B;
		cin >> A >> B;
		if (A % B != 0) {
			cout << -M << '\n';
			continue;
		}
		int mx = Pc[A / B];
		for (int j = 1; j <= mx; j++) {
			best2[j] = inf;
		}
		for (int j = 1; j <= T; j++) {
			best3[j] = inf;
			if (A % X[j] != 0 || X[j] % B != 0) {
				continue;
			}
			int Ad = A / X[j];
			int Bd = X[j] / B;
			for (int k = 1; k <= mx; k++) {
				best1[k] = inf;
			}
			for (int x = 0; x <= Pc[Ad]; x++) {
				for (int y = 0; y <= Pc[Bd]; y++) {
					best1[x + y] = min(best1[x + y], dp[Ad][x] + dp[Bd][y]);
				}
			}
			for (int k = 1; k <= mx; k++) {
				best3[j] = min(best3[j] + C[j], best1[k]);
				best2[k] = min(best2[k], best3[j]);
			}
		}
		long long res = 0;
		for (int j = 1; j <= M; j++) {
			if (L[j] <= mx) {
				if (best2[L[j]] == inf) {
					res += -1;
				}
				else {
					res += best2[L[j]];
				}
			}
			else {
				int cur = inf;
				for (int k = 1; k <= T; k++) {
					cur = min(cur, (L[j] - mx) * C[k] + best3[k]);
				}
				if (cur == inf) {
					res += -1;
				}
				else {
					res += cur;
				}
			}
		}
		cout << res << '\n';
	}
}

// END MAIN CODE

Compilation message

gauss.cpp: In function 'void file_io(std::string, std::string)':
gauss.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   freopen(fi.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
gauss.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen(fo.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 524 ms 94360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 545 ms 94264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 504 ms 94256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 494 ms 94136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1016 ms 95176 KB Output is correct
2 Incorrect 1095 ms 95024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1295 ms 95016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 886 ms 95196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1924 ms 95480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2087 ms 94984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2077 ms 95168 KB Time limit exceeded
2 Halted 0 ms 0 KB -