Submission #849917

#TimeUsernameProblemLanguageResultExecution timeMemory
849917MuntherCarrotOvertaking (IOI23_overtaking)C++17
65 / 100
3525 ms31820 KiB
// by me #include "overtaking.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define all(x) x.begin(), x.end() const int MOD = 1e9 + 7, SZ = 1e5 + 10, INF = 1e9; vector<vector<ll>> vec, dp; vector<int> w, s; vector<ll> t; int n, m, x; void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S) { n = N, m = M, w = W, s = S, t = T, x = X; vec.assign(M, vector<ll>(N)); dp.assign(M, vector<ll>(N, 0)); vector<pair<ll, int>> vv(n); for(int i = 0; i < n; i++){ if(w[i] <= X) continue; vv[i] = {t[i], w[i]}; } sort(all(vv)); for(int i = 0; i < n; i++){ vec[0][i] = vv[i].first; } for(int j = 1; j < m; j++){ sort(all(vv)); for(int i = 0; i < n; i++){ vv[i].first += 1ll * vv[i].second * (s[j] - s[j - 1]); if(i){ vv[i].first = max(vv[i].first, vv[i - 1].first); } vec[j][i] = vv[i].first; } } for(int j = m - 1; j >= 0; j--){ for(int i = n - 1; i >= 0; i--){ int _i = lower_bound(all(vec[j]), vec[j][i]) - vec[j].begin(); if(j == m - 1 || _i == 0){ dp[j][i] = vec[j][i] + x * (s[m - 1] - s[j]); continue; } dp[j][i] = dp[j + 1][_i - 1]; } } // for(int j = 0; j < m; j++){ // for(int i = 0; i < n; i++){ // cout << vec[j][i] << ' '; // } // cout << endl; // } return; } long long arrival_time(long long Y) { ll ans = Y; int idx = lower_bound(all(vec[0]), ans) - vec[0].begin(); if(idx == 0){ return 1ll * x * s[m - 1] + Y; } for(int j = 0; j < m; j++){ ll f = 1ll * x * (s[j] - (j ? s[j - 1] : 0)); if(idx && vec[j][idx - 1] > ans + f){ ans = vec[j][idx - 1]; } else ans += f; // while(idx && vec[j][idx - 1] >= ans) idx--; idx = lower_bound(all(vec[j]), ans) - vec[j].begin(); } return ans; } // int32_t main(){ // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // 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]); // // for (int i = 0; i < Q; i++) // printf("%lld\n", res[i]); // // fclose(stdout); // return 0; // } // by me
#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...