# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
219370 | ho94949 | Treatment Project (JOI20_treatment) | C++17 | 318 ms | 196472 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 5000;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int N, M;
int T[MAXM+2], L[MAXM+2], R[MAXM+2], C[MAXM+2];
long long cost[MAXM+2][MAXM+2];
long long dist[MAXM+2];
bool vis[MAXM+2];
long long dijk(int N, int s, int e)
{
memset(dist, 0x3f, sizeof dist);
memset(vis, 0, sizeof vis);
dist[s] = 0;
for(int _=0; _<N; _++)
{
int mini = -1; long long minv = INF;
for(int i=0; i<N; ++i)
if(!vis[i] && minv>dist[i])
mini = i, minv = dist[i];
if(mini == -1) return -1;
if(mini == e) return minv;
vis[mini] = true;
for(int i=0; i<N; ++i)
dist[i] = min(dist[i], dist[mini]+cost[mini][i]);
}
return -1;
}
int main()
{
scanf("%d%d", &N, &M);
for(int i=1; i<=M; ++i)
{
scanf("%d%d%d%d", T+i, L+i, R+i, C+i);
--L[i]; //L[i] = 0, R[i] = N covers whole
}
memset(cost, 0x3f, sizeof cost);
for(int i=1; i<=M; ++i)
{
if(L[i] == 0) cost[0][i] = C[i];
if(R[i] == N) cost[i][M+1] = 0;
}
for(int i=1; i<=M; ++i)
{
for(int j=1; j<=M; ++j)
{
if(i==j) continue;
if(R[i] - abs(T[i]-T[j]) >= L[j])
cost[i][j] = C[j];
}
}
long long ans = dijk(M+2, 0, M+1);
printf("%lld\n", ans);
}
Compilation message (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... |