# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
696434 | 2023-02-06T13:56:29 Z | SanguineChameleon | Gauss (COCI17_gauss) | C++17 | 2000 ms | 94848 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 d = A / B; int mx = Pc[d]; for (int j = 1; j <= mx; j++) { best2[j] = dp[d][j]; } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 467 ms | 94156 KB | Output is correct |
2 | Correct | 467 ms | 94248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 474 ms | 94248 KB | Output is correct |
2 | Correct | 469 ms | 94264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 501 ms | 94252 KB | Output is correct |
2 | Correct | 456 ms | 94212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 492 ms | 94244 KB | Output is correct |
2 | Correct | 509 ms | 94248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1014 ms | 94624 KB | Output is correct |
2 | Correct | 1040 ms | 94652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1284 ms | 94528 KB | Output is correct |
2 | Correct | 1176 ms | 94796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 883 ms | 94596 KB | Output is correct |
2 | Execution timed out | 2091 ms | 94848 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1899 ms | 94716 KB | Output is correct |
2 | Correct | 805 ms | 94576 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2086 ms | 94636 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2074 ms | 94708 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |