Submission #966549

#TimeUsernameProblemLanguageResultExecution timeMemory
966549nguyentunglam추월 (IOI23_overtaking)C++17
65 / 100
3539 ms22608 KiB
#include "overtaking.h" #include<bits/stdc++.h> using namespace std; const int N = 1010; int n, m; int order[N], _order[N][N]; long long t[N], w[N], s[N], f[N][N], g[N][N]; 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; for(int i = 0; i < n; i++) w[i] = W[i], t[i] = T[i]; for(int i = 0; i < m; i++) s[i] = S[i]; w[n] = X; for(int i = 0; i < n; i++) order[i] = i; for(int i = 0; i < n; i++) f[i][0] = t[i]; for(int j = 1; j < m; j++) { sort(order, order + n, [&] (const int &x, const int &y) { if (f[x][j - 1] != f[y][j - 1]) return f[x][j - 1] < f[y][j - 1]; return w[x] < w[y]; }); long long slowest = 0; for(int cur = 0; cur < n; cur++) { int i = order[cur]; f[i][j] = max(slowest, f[i][j - 1] + w[i] * (s[j] - s[j - 1])); slowest = f[i][j]; } } for(int j = 1; j < m; j++) { sort(order, order + n, [&] (const int &x, const int &y) { if (f[x][j - 1] != f[y][j - 1]) return f[x][j - 1] < f[y][j - 1]; return w[x] < w[y]; }); for(int cur = 0; cur < n; cur++) { int i = order[cur]; g[j][cur] = f[i][j]; if (cur) g[j][cur] = max(g[j][cur], g[j][cur - 1]); } for(int i = 0; i < n; i++) _order[i][j] = order[i]; } } long long arrival_time(long long Y) { long long pre = Y; for(int j = 1; j < m; j++) { int l = 0, r = n - 1, last = -1; while (l <= r) { int mid = l + r >> 1; int k = _order[mid][j]; if (pre > f[k][j - 1]) { last = mid; l = mid + 1; } else r = mid - 1; } long long nxt = pre + w[n] * (s[j] - s[j - 1]); if (last != -1) { nxt = max(nxt, g[j][last]); } pre = nxt; // cout << pre << " "; } return pre; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); 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; } #endif // ngu

Compilation message (stderr)

overtaking.cpp: In function 'long long int arrival_time(long long int)':
overtaking.cpp:52:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |       int mid = l + r >> 1;
      |                 ~~^~~
#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...