Submission #855126

#TimeUsernameProblemLanguageResultExecution timeMemory
855126FairyWinxOvertaking (IOI23_overtaking)C++17
19 / 100
3 ms856 KiB
#include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using namespace std; vector<vector<long long>> res; vector<int> s; vector<pair<int, long long>> t; // speed, time int n, m; int x; vector<vector<int>> pos_layer; vector<vector<int>> who_layer; vector<vector<int>> nxt_in_layer; vector<vector<long long>> res_layer; void init(int l, int _n, vector<long long> _t, vector<int> _w, int _x, int _m, vector<int> _s) { x = _x, n = _n, m = _m; s = _s; t.resize(n); for (int i = 0; i < n; ++i) { t[i].first = _w[i]; t[i].second = _t[i]; } sort(rall(t)); while (t.size() && t.back().first <= x) { t.pop_back(); } n = t.size(); pos_layer.resize(m, vector<int> (n)); who_layer.resize(m, vector<int> (n)); nxt_in_layer.resize(m, vector<int> (n, -1)); res_layer.resize(m, vector<long long> (n)); res.resize(m, vector<long long> (n, -1)); s = _s; for (int i = 0; i < n; ++i) { res[0][i] = t[i].second; } for (int i = 0; i < m - 1; ++i) { for (int j = 0; j < n; ++j) { long long s1 = 1ll * (s[i + 1] - s[i]) * t[j].first; res[i + 1][j] = res[i][j] + s1; for (int k = 0; k < j; ++k) { if (res[i][j] > res[i][k] && res[i][j] + s1 < res[i + 1][k]) { res[i + 1][j] = max(res[i + 1][j], res[i + 1][k]); } } } } for (int i = 0; i < m; ++i) { vector<int> p(n); iota(all(p), 0); sort(p.begin(), p.end(), [&] (const int &a, const int &b) { return make_pair(res[i][a], a) < make_pair(res[i][b], b); }); for (int j = 0; j < n; ++j) { pos_layer[i][p[j]] = j; who_layer[i][j] = p[j]; } for (int j = 0; j < n; ++j) { for (int k = j - 1; k >= 0; --k) { if (res[i][who_layer[i][j]] > res[i][who_layer[i][k]]) { nxt_in_layer[i][j] = k; break; } } } } for (int i = 0; i < n; ++i) { res_layer[m - 1][pos_layer[m - 1][i]] = res[m - 1][i]; } for (int i = m - 2; i >= 0; --i) { for (int j = 0; j < n; ++j) { // y = res[i][j]. int ind_j = pos_layer[i][j]; if (nxt_in_layer[i][ind_j] == -1) { res_layer[i][pos_layer[i][j]] = res[i][j] + 1ll * x * (s.back() - s[i]); continue; } int ind_less = who_layer[i][nxt_in_layer[i][ind_j]]; for (int k = i + 1; k < m; ++k) { if (res[k][ind_less] >= res[i][j] + 1ll * x * (s[k] - s[i])) { res_layer[i][pos_layer[i][j]] = res_layer[k][pos_layer[k][ind_less]]; } else if (k == m - 1) { res_layer[i][pos_layer[i][j]] = res[i][j] + 1ll * x * (s[k] - s[i]); } } } } } long long arrival_time(long long y) { int ind = -1; for (int i = 0; i < n; ++i) { if (res[0][who_layer[0][i]] < y) ind = who_layer[0][i]; } if (ind == -1) { return 1ll * x * (s.back()) + y; } for (int i = 0; i < m; ++i) { if (1ll * x * s[i] + y <= res[i][ind]) { return res_layer[i][pos_layer[i][ind]]; } } return 1ll * x * s.back() + y; } #ifdef LOCAL int main() { // BEGIN SECRET const std::string input_secret = "XwWPuInrOjpekAwGKojzwKw3yVDtdkGS"; const std::string output_secret = "mGlgT4yvr1qPbquFwkxRVh9hMn0Mrxoz"; char secret[1000]; assert(1 == scanf("%999s", secret)); if (std::string(secret) != input_secret) { printf("%s\n", output_secret.c_str()); printf("PV\n"); printf("Possible tampering with the input\n"); fclose(stdout); return 0; } // END SECRET int L, N, X, M, Q; assert(5 == scanf("%d %d %d %d %d", &L, &N, &X, &M, &Q)); std::vector<long long> T(N); for (int i = 0; i < N; i++) assert(1 == scanf("%lld", &T[i])); std::vector<int> W(N); for (int i = 0; i < N; i++) assert(1 == scanf("%d", &W[i])); std::vector<int> S(M); for (int i = 0; i < M; i++) assert(1 == scanf("%d", &S[i])); std::vector<long long> Y(Q); for (int i = 0; i < Q; i++) assert(1 == scanf("%lld", &Y[i])); fclose(stdin); init(L, N, T, W, X, M, S); std::vector<long long> res(Q); for (int i = 0; i < Q; i++) res[i] = arrival_time(Y[i]); // BEGIN SECRET printf("%s\n", output_secret.c_str()); printf("OK\n"); // END SECRET for (int i = 0; i < Q; i++) printf("%lld\n", res[i]); fclose(stdout); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...