Submission #584956

# Submission time Handle Problem Language Result Execution time Memory
584956 2022-06-28T07:38:55 Z 조영욱(#8382) 도장 모으기 (JOI14_stamps) C++14
85 / 100
106 ms 143756 KB
#include <bits/stdc++.h>
using namespace std;

int n;
long long t;
long long dp[3002];
long long u[3002];
long long v[3002];
long long d[3002];
long long e[3002];
long long dist[3003][3003];
const long long INF=1e15;

long long f(int l,int r) {
    if (l>r) {
        return 0;
    }
    long long ret=0;
    for(int i=l;i<=r;i++) {
        //printf("%d\n",i);
        ret+=min(u[i]+v[i],dist[3*i][3*i+1]+dist[3*i+1][3*i+2]+dist[3*i+2][3*i]);
    }
    return ret;
}

long long g(int l,int r) {
    if (l>r) {
        return 0;
    }
    long long ret=0;
    for(int i=l;i<=r;i++) {
        //printf("%d\n",i);
        ret+=min({u[i]+v[i],dist[3*i][3*i+1]+dist[3*i+1][3*i+2]+dist[3*i+2][3*i],d[i]+e[i],dist[3*i+2][3*i+1]+dist[3*i+1][3*i]+dist[3*i][3*i+2]});
    }
    return ret;
}

int main(void) {
    scanf("%d %lld",&n,&t);
    for(int i=1;i<=n;i++) {
        scanf("%lld %lld %lld %lld",&u[i],&v[i],&d[i],&e[i]);
    }
    for(int i=0;i<=3*n+5;i++) {
        for(int j=0;j<=3*n+5;j++){
            dist[i][j]=INF;
            if (i==j){
                dist[i][j]=0;
                continue;
            }
        }
    }
    for(int i=0;i<=n+1;i++) {
        if (i<=n) {
            dist[3*i][3*i+3]=t;
        }
        if (i>0) {
            dist[3*i+2][3*i-1]=t;
        }
        if (i==0||i==n+1) {
            continue;
        }
        dist[3*i][3*i+1]=u[i];
        dist[3*i+1][3*i]=v[i];
        dist[3*i+1][3*i+2]=e[i];
        dist[3*i+2][3*i+1]=d[i];
    }
    for(int k=0;k<3*n+6;k++) {
        for(int i=0;i<3*n+6;i++) {
            for(int j=0;j<3*n+6;j++) {
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    //printf("%lld\n",f(4,4));
    for(int i=1;i<=n+1;i++) {
        dp[i]=1e18;
        for(int j=0;j<i;j++) {
if (i==n+1) continue;
            for(int k=1;k<i;k++) {
                dp[i]=min(dp[i],dp[j]+f(j+1,k-1)+v[k]+d[k]+g(max(j+1,k+1),i-1)+u[i]+e[i]+(i-j)*t+2*(i-k)*t);
                //printf("%d %d %d %lld\n",i,j,k,dp[j]+f(j+1,k-1)+v[k]+d[k]+g(max(j+1,k+1),i-1)+u[i]+e[i]+(i-j)*t+2*(i-k)*t);
                //printf(".%d %lld\n",i,dp[i]);
            }
            //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]+f(i,i)+t);
        //printf("%lld\n",dp[i]);
    }
    printf("%lld",dp[n+1]);
}

Compilation message

stamps.cpp: In function 'int main()':
stamps.cpp:78:1: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   78 | if (i==n+1) continue;
      | ^~
stamps.cpp:79:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   79 |             for(int k=1;k<i;k++) {
      |             ^~~
stamps.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d %lld",&n,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~
stamps.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         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 468 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 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 2004 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 67 ms 2264 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 21 ms 1288 KB Output is correct
7 Correct 48 ms 2004 KB Output is correct
8 Correct 60 ms 2184 KB Output is correct
9 Correct 67 ms 2208 KB Output is correct
10 Correct 65 ms 2260 KB Output is correct
11 Correct 67 ms 2264 KB Output is correct
12 Correct 72 ms 2272 KB Output is correct
13 Correct 80 ms 2304 KB Output is correct
14 Correct 99 ms 2264 KB Output is correct
15 Correct 83 ms 2272 KB Output is correct
16 Correct 68 ms 2268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 106 ms 143756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -