Submission #520423

#TimeUsernameProblemLanguageResultExecution timeMemory
520423ajpianoLong Distance Coach (JOI17_coach)C++17
0 / 100
1 ms336 KiB
//https://oj.uz/problem/view/JOI17_coach #include <bits/stdc++.h> using namespace std; #define f first #define s second typedef long long ll; typedef pair<ll, ll> pi; int main() { ios_base::sync_with_stdio(0); cin.tie(0); //remember to include destination in dp //remember to add driver cost ll x, w, t; int n,m; cin >> x >> n >> m >> w >> t; //Total time, cities, people, water cost, time interval vector<ll> stops(n+1); //where the coach stops for(int i = 0; i < n; i++) cin >> stops[i]; stops[n] = x; vector<pi> passengers(m+1); // water time, refund cost for(int i = 1; i <= m; i++) cin >> passengers[i].f >> passengers[i].s; sort(passengers.begin(), passengers.end()); //find from where you can go back on a passenger vector<int> goback(m+1,-1); for(int i = n; i >= 0; i--){ ll pos = stops[i]%t; pi fnd = {pos,0}; int cur = lower_bound(passengers.begin(), passengers.end(), fnd) - passengers.begin()-1; //passenger you can go back from goback[cur] = i; } //find coefficient for each stop vector<ll> coe(n+1); for(int i = 0; i <= n; i++) coe[i] = w*(stops[i]/t); //find full cost for each passenger vector<ll> cost(m+1); for(int i = 0; i <= m; i++){ cost[i] = w*((x-passengers[i].f)/t+1LL)-passengers[i].s; } ll ans = 0; //assume you refund everyone for(int i = 0; i <= m; i++) ans += passengers[i].s; //add driver cost ans += cost[0]; vector<ll> dp(m+2); //do dp for(int i = m; i > 0; i--){ dp[i] = cost[i]+dp[i+1]; for(int j = i; j <= m; j++){ if(goback[j] == -1) continue; ll dist = j-i+1; int stop = goback[j]; ll pcur = dp[i]; dp[i] = min(dp[i], dp[j+1]+dist*coe[stop]); } } //give ans cout << ans+dp[1] << "\n"; return 0; }

Compilation message (stderr)

coach.cpp: In function 'int main()':
coach.cpp:61:16: warning: unused variable 'pcur' [-Wunused-variable]
   61 |             ll pcur = dp[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...