# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
696432 | 2023-02-06T13:51:55 Z | SanguineChameleon | Gauss (COCI17_gauss) | C++17 | 2000 ms | 95128 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 + i, d = 2; 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 = 0; 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 = 0; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 533 ms | 94248 KB | Output is correct |
2 | Correct | 475 ms | 94252 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 473 ms | 94244 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 528 ms | 94276 KB | Output is correct |
2 | Correct | 447 ms | 94256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 486 ms | 94292 KB | Output is correct |
2 | Correct | 457 ms | 94248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1040 ms | 94756 KB | Output is correct |
2 | Correct | 1065 ms | 94648 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1286 ms | 94616 KB | Output is correct |
2 | Correct | 1259 ms | 95128 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 964 ms | 94636 KB | Output is correct |
2 | Execution timed out | 2068 ms | 95104 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1888 ms | 94728 KB | Output is correct |
2 | Correct | 746 ms | 95068 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2077 ms | 94552 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2084 ms | 94632 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |