# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
49366 | SpaimaCarpatilor | Long Distance Coach (JOI17_coach) | C++17 | 3 ms | 520 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int N, M, W, T, how[200009];
long long X, dp[200009], need[200009];
const long long INF = 1LL << 60;
pair < int, long long > station[200009];
pair < long long, int > passenger[200009];
void read ()
{
scanf ("%lld %d %d %d %d", &X, &N, &M, &W, &T);
for (int i=1; i<=N; i++)
scanf ("%lld", &station[i].second), station[i].first = station[i].second % T;
if (X % T != 0)
station[++N] = {X % T, X};
sort (station + 1, station + N + 1);
for (int i=1; i<=M; i++)
scanf ("%d %d", &passenger[i].first, &passenger[i].second);
sort (passenger + 1, passenger + M + 1);
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
read ();
for (int i=1; i<=M; i++)
need[i] = 1LL * W * ((X - passenger[i].first) / T + 1);
for (int i=0; i<=M; i++)
dp[i] = INF;
dp[M + 1] = 1LL * W * (X / T + 1);///dp[i] = i gets there (in our case the driver) and I've already considered all those with higher residuum
passenger[M + 1].first = T + 1;
for (int i=M + 1; i>=1; i--)
{
if (dp[i] + need[i - 1] < dp[i - 1])
dp[i - 1] = dp[i] + need[i - 1], how[i - 1] = i;
int pntr = N + 1;
long long fastestAbort = X + 1;
/*while (pntr > 1 && station[pntr - 1].first > passenger[i].first)
pntr --; without this, the source should be wrong*/
///I want to ignore those starting at pntr cause they would all abort i as well
long long curr = dp[i];
for (int j=i - 1; j>=1; j--)
{
///assume you've aborted all passengers in range [j, i - 1]
while (pntr > 1 && station[pntr - 1].first > passenger[j].first)
pntr --, fastestAbort = min (fastestAbort, station[pntr].second);
if (station[pntr].first <= passenger[j].first || station[pntr].first > passenger[i].first) break;
curr += passenger[j].second;
if (fastestAbort > passenger[j].first)
curr += 1LL * W * ((fastestAbort - passenger[j].first) / T);
if (curr + need[j - 1] < dp[j - 1])
dp[j - 1] = curr + need[j - 1], how[j - 1] = i;
}
}
printf ("%lld\n", dp[0]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |