Submission #585060

#TimeUsernameProblemLanguageResultExecution timeMemory
585060urd05도장 모으기 (JOI14_stamps)C++17
0 / 100
189 ms141564 KiB
#include <bits/stdc++.h> using namespace std; int n; long long t; long long dp[100005]; long long u[100005]; long long v[100005]; long long d[100005]; long long e[100005]; const long long INF=2e14; const int sz=8192; long long v1[3001]; long long v2[3001]; long long r1[3001][3001]; long long r2[3001][3001]; long long f[100005]; long long g[100005]; int main(void) { scanf("%d %lld",&n,&t); assert(n<=3000); for(int i=1;i<=n;i++) { scanf("%lld %lld %lld %lld",&u[i],&v[i],&d[i],&e[i]); } for(int i=1;i<=n;i++) { f[i]=f[i-1]+u[i]+v[i]; g[i]=g[i-1]+min(u[i]+v[i],d[i]+e[i]); } for(int i=1;i<=n;i++) { v1[i]=v[i]+d[i]-2*t*i; v2[i]=f[i-1]+v[i]+d[i]-g[i]-2*t*i; } for(int i=1;i<=n;i++) { for(int j=1;j<i;j++) { r1[i][j]=INF; r2[i][j]=INF; } for(int j=i;j<=n;j++) { r1[i][j]=min(r1[i][j-1],v1[j]); r2[i][j]=min(r2[i][j-1],v2[j]); } } for(int i=1;i<=n+1;i++) { dp[i]=INF; for(int j=0;j<i;j++) { if (i==n+1) continue; dp[i]=min(dp[i],dp[j]-f[j]+g[i-1]+u[i]+e[i]+(i-j)*t+2*i*t+r2[j+1][i-1]); dp[i]=min(dp[i],dp[j]+g[i-1]-g[j]+u[i]+e[i]+(i-j)*t+2*i*t+r1[1][j]); //printf("%d %d %lld\n",i,j,dp[j]+f(j+1,i==n+1?n:i)+(i-j)*t); //printf(".%d %lld\n",i,dp[i]); } dp[i]=min(dp[i],dp[i-1]+u[i]+v[i]+t); //printf("%lld\n",dp[i]); } long long ret=dp[n+1]; reverse(u+1,u+n+1); reverse(v+1,v+n+1); reverse(d+1,d+n+1); reverse(e+1,e+n+1); for(int i=1;i<=n;i++) { swap(u[i],v[i]); swap(d[i],e[i]); f[i]=f[i-1]+u[i]+v[i]; g[i]=g[i-1]+min(u[i]+v[i],d[i]+e[i]); v1[i]=v[i]+d[i]-2*t*i; v2[i]=f[i-1]+v[i]+d[i]-g[i]-2*t*i; } for(int i=1;i<=n;i++) { for(int j=1;j<i;j++) { r1[i][j]=INF; r2[i][j]=INF; } for(int j=i;j<=n;j++) { r1[i][j]=min(r1[i][j-1],v1[j]); r2[i][j]=min(r2[i][j-1],v2[j]); } } for(int i=1;i<=n+1;i++) { dp[i]=INF; for(int j=0;j<i;j++) { if (i==n+1) continue; dp[i]=min(dp[i],dp[j]-f[j]+g[i-1]+u[i]+e[i]+(i-j)*t+2*i*t+r2[j+1][i-1]); dp[i]=min(dp[i],dp[j]+g[i-1]-g[j]+u[i]+e[i]+(i-j)*t+2*i*t+r1[1][j]); //printf("%d %d %lld\n",i,j,dp[j]+f(j+1,i==n+1?n:i)+(i-j)*t); //printf(".%d %lld\n",i,dp[i]); } dp[i]=min(dp[i],dp[i-1]+u[i]+v[i]+t); //printf("%lld\n",dp[i]); } ret=max(ret,dp[n+1]); printf("%lld",ret); }

Compilation message (stderr)

stamps.cpp: In function 'int main()':
stamps.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d %lld",&n,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~
stamps.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%lld %lld %lld %lld",&u[i],&v[i],&d[i],&e[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...