# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
585051 |
2022-06-28T09:29:15 Z |
조영욱(#8382) |
도장 모으기 (JOI14_stamps) |
C++14 |
|
183 ms |
141484 KB |
#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=2e9;
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=min(ret,dp[n+1]);
printf("%lld",ret);
}
Compilation message
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 time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1220 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
560 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
141372 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
182 ms |
141484 KB |
Output is correct |
4 |
Correct |
143 ms |
124896 KB |
Output is correct |
5 |
Correct |
111 ms |
103500 KB |
Output is correct |
6 |
Incorrect |
50 ms |
48176 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |