제출 #884207

#제출 시각아이디문제언어결과실행 시간메모리
884207DAleksaLong Distance Coach (JOI17_coach)C++17
0 / 100
1 ms12632 KiB
#include <bits/stdc++.h> using namespace std; #define int long long struct Line { int a; int b; long long eval(int x) { return a * 1LL * x + b; } }; const int N = 2e5 + 10; long long X, T; int n, m, W; long long a[N]; long long b[N], B[N]; long long c[N], C[N]; int order[N]; long long pref[N]; __int128 dp[N]; long long ind[N]; long long cnt[N]; vector<Line> lines; vector<long long> all; map<long long, int> start_to_index; long long get(int x) { long long ans = 1e18; for(Line l : lines) ans = min(ans, l.eval(x)); return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> X >> n >> m >> W >> T; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for(int i = 1; i <= m; i++) cin >> B[i] >> C[i]; for(int i = 1; i <= m; i++) order[i] = i; sort(order + 1, order + m + 1, [&](int i, int j) { return B[i] < B[j]; }); for(int i = 1; i <= m; i++) { b[i] = B[order[i]]; c[i] = C[order[i]]; all.push_back(b[i]); start_to_index[b[i]] = i; pref[i] = pref[i - 1] + c[i]; cnt[i] = X / T + (b[i] <= X % T); ind[i] = -1; } sort(all.begin(), all.end()); n++; a[n] = X; // for(int i : all) cout << i << " "; // cout << "\n"; for(int i = n; i >= 1; i--) { int temp = a[i] % T; int index = lower_bound(all.begin(), all.end(), temp) - all.begin(); index--; if(index == -1) continue; ind[start_to_index[(a[i] - (temp - all[index])) % T]] = a[i] - (temp - all[index]); } // for(int i = 1; i <= m; i++) cout << ind[i] << " "; // cout << "\n"; // for(int i = 1; i <= m; i++) cout << cnt[i] << " "; // cout << "\n"; for(int i = 1; i <= m; i++) { dp[i] = dp[i - 1] + W * cnt[i]; if(ind[i] != -1) dp[i] = min(dp[i], (__int128)get(W * (ind[i] / T)) + pref[i] + W * i * (ind[i] / T)); lines.push_back({-i, dp[i] - pref[i]}); } // for(int i = 1; i <= m; i++) cout << dp[i] << " "; // cout << "\n"; cout << (long long)(dp[m] + (X / T + 1) * W); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

coach.cpp: In function 'int main()':
coach.cpp:74:30: warning: narrowing conversion of '(dp[i] - ((__int128)pref[i]))' from '__int128' to 'long long int' [-Wnarrowing]
   74 |   lines.push_back({-i, dp[i] - pref[i]});
      |                        ~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...