# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1079306 | sjb8032 | Marathon Race 2 (JOI24_ho_t3) | C++17 | 0 ms | 348 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;
int n,q;
long long x[2005];
long long dpL[2005][2005][2];
long long dpR[2005][2005][2];
long long s,g,t;
const long long INF=LONG_MAX;
long long ans;
int main()
{
scanf("%d %d",&n,&q);
for(int i=1; i<=n; i++)
{
scanf("%lld",&x[i]);
}
sort(x+1,x+n+1);
scanf("%d",&q);
for(int i=0; i<=n+1; i++)
{
for(int j=0; j<=n+1; j++)
{
dpL[i][j][0]=INF;
dpL[i][j][1]=INF;
dpR[i][j][0]=INF;
dpR[i][j][1]=INF;
}
}
dpL[1][n+1][0]=0;
dpR[0][n][1]=0;
for(int i=0;i<=n;i++)
{
for(int j=n+1;j>i;j--)
{
int carry=i+(n+1-j)+1;
if(i+1<j)
{
dpL[i+1][j][0]=min(dpL[i+1][j][0],min(dpL[i][j][0]+carry*(x[i+1]-x[i]),dpL[i][j][1]+carry*(x[j]-x[i+1])));
dpR[i+1][j][0]=min(dpR[i+1][j][0],min(dpR[i][j][0]+carry*(x[i+1]-x[i]),dpR[i][j][1]+carry*(x[j]-x[i+1])));
}
if(i<j-1)
{
dpL[i][j-1][1]=min(dpL[i][j-1][1],min(dpL[i][j][0]+carry*(x[j-1]-x[i]),dpL[i][j][1]+carry*(x[j]-x[j-1])));
dpR[i][j-1][1]=min(dpR[i][j-1][1],min(dpR[i][j][0]+carry*(x[j-1]-x[i]),dpR[i][j][1]+carry*(x[j]-x[j-1])));
}
}
}
for(int i=1; i<=q; i++)
{
scanf("%lld %lld %lld",&s,&g,&t);/// g를 기준으로 왼,오 1,2,3,...,l,r,r+1,...,n
if(n==1)
{
ans=abs(s-x[1])+2*abs(x[1]-g);
ans++;
if(ans<=t) printf("Yes\n");
else printf("No\n");
continue;
}
int k=lower_bound(x+1,x+n+1,g)-x;///g 이상 처음나오는 값의 위치 k번째 왼쪽 k-1-> g 또는 오른쪽 k에서 g k->g
long long Lmin=min(dpL[k-1][k][0]+(n+1)*abs(g-x[k-1]),dpL[k-1][k][1]+(n+1)*abs(g-x[k]))+abs(s-x[1]);
long long Rmin=min(dpR[k-1][k][0]+(n+1)*abs(g-x[k-1]),dpR[k-1][k][1]+(n+1)*abs(g-x[k]))+abs(s-x[n]);
ans=min(Rmin,Lmin)+n;
if(ans<=t) printf("Yes\n");
else printf("No\n");
}
return 0;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |