Submission #1079306

#TimeUsernameProblemLanguageResultExecution timeMemory
1079306sjb8032Marathon Race 2 (JOI24_ho_t3)C++17
0 / 100
0 ms348 KiB
#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)

Main.cpp: In function 'int main()':
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%lld",&x[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
Main.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%lld %lld %lld",&s,&g,&t);/// g를 기준으로 왼,오 1,2,3,...,l,r,r+1,...,n
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...