답안 #584849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584849 2022-06-28T05:05:38 Z 반딧불(#8380) 도장 모으기 (JOI14_stamps) C++14
10 / 100
114 ms 143516 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k; ll t;
ll uin[3002], uout[3002], din[3002], dout[3002];
ll dist[3002][3002];
ll d[3002][3002];
ll DP[1<<17][17];
ll ans = 1e18;

int main(){
    scanf("%d %lld", &n, &t);
    k = n*3+6;
    for(int i=1; i<=k; i++) for(int j=1; j<=k; j++) dist[i][j] = (i==j) ? 0 : 1e18;
    for(int i=0; i<=n; i++){
        dist[3*i+3][3*i+6] = t;
        dist[3*i+4][3*i+1] = t;
    }
    dist[1][2] = dist[2][1] = dist[2][3] = dist[3][2] = 0;
    dist[k-1][k-2] = dist[k-2][k-1] = dist[k][k-1] = dist[k-1][k] = 0;

    for(int i=1; i<=n; i++){
        scanf("%lld %lld %lld %lld", &uin[i], &uout[i], &din[i], &dout[i]);
        dist[3*i+3][3*i+2] = uin[i];
        dist[3*i+2][3*i+3] = uout[i];
        dist[3*i+1][3*i+2] = din[i];
        dist[3*i+2][3*i+1] = dout[i];
    }

    for(int x=4; x<=k-3; x++){
        for(int y=4; y<=k-3; y++){
            for(int z=4; z<=k-3; z++){
                dist[y][z] = min(dist[y][z], dist[y][x] + dist[x][z]);
            }
        }
    }

    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++){
        d[i][j] = dist[i*3+2][j*3+2];
    }
    for(int i=1; i<=n; i++){
        d[0][i] = t*i + dist[i*3+3][i*3+2];
        d[i][n+1] = dist[i*3+2][i*3+3] + t*(n+1-i);
    }

    for(int i=0; i<(1<<17); i++) for(int j=0; j<17; j++) DP[i][j] = 1e18;
    DP[1][0] = 0;
    for(int b=1; b<(1<<(n+1)); b++){
        for(int i=0; i<=n; i++){
            if(!((b>>i)&1) || DP[b][i] >= 1e18) continue;
            for(int j=0; j<=n; j++){
                if((b>>j)&1) continue;
                DP[b+(1<<j)][j] = min(DP[b+(1<<j)][j], DP[b][i] + d[i][j]);
            }
        }
    }
    for(int i=1; i<=n; i++){
        ans = min(ans, DP[(1<<(n+1))-1][i] + d[i][n+1]);
    }

    printf("%lld", ans);
}

Compilation message

stamps.cpp: In function 'int main()':
stamps.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %lld", &n, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
stamps.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%lld %lld %lld %lld", &uin[i], &uout[i], &din[i], &dout[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17876 KB Output is correct
2 Correct 8 ms 17788 KB Output is correct
3 Correct 40 ms 18064 KB Output is correct
4 Correct 18 ms 18004 KB Output is correct
5 Correct 39 ms 17984 KB Output is correct
6 Correct 11 ms 18004 KB Output is correct
7 Correct 15 ms 18004 KB Output is correct
8 Correct 22 ms 18004 KB Output is correct
9 Correct 39 ms 18004 KB Output is correct
10 Correct 41 ms 18004 KB Output is correct
11 Correct 40 ms 18060 KB Output is correct
12 Correct 45 ms 18068 KB Output is correct
13 Correct 43 ms 18060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 40240 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 114 ms 143516 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -