Submission #585060

# Submission time Handle Problem Language Result Execution time Memory
585060 2022-06-28T09:36:39 Z urd05 도장 모으기 (JOI14_stamps) C++17
0 / 100
189 ms 141564 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=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

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 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Incorrect 1 ms 468 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 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 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Incorrect 1 ms 1236 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 189 ms 141356 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 186 ms 141564 KB Output is correct
4 Correct 154 ms 124864 KB Output is correct
5 Correct 116 ms 103500 KB Output is correct
6 Incorrect 48 ms 48076 KB Output isn't correct
7 Halted 0 ms 0 KB -