# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
584895 | 2022-06-28T06:24:55 Z | 반딧불(#8380) | 도장 모으기 (JOI14_stamps) | C++14 | 114 ms | 143588 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 ans = 1e18; ll sumD[3002][3002]; ll DP[3002][3002]; 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=1; i<=n; i++){ for(int j=i-1; j>=1; j--){ sumD[i][j] = sumD[i][j+1] + d[j+1][j]; } } for(int i=0; i<=n+1; i++) for(int j=0; j<=n+1; j++) DP[i][j] = 1e18; DP[0][0] = 0; for(int i=1; i<=n; i++){ for(int j=0; j<i; j++){ /// �������� j DP[i][i] = min(DP[i][i], DP[i-1][j] + d[j][i]); if(j){ for(int x=0; x<j; x++){ if(j-1 && !x) continue; DP[i][j] = min(DP[i][j], DP[j-1][x] + d[x][i] + sumD[i][j]); } } } } for(int i=1; i<=n; i++){ ans = min(ans, DP[n][i] + d[i][n+1]); } printf("%lld", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 724 KB | Output is correct |
4 | Correct | 1 ms | 724 KB | Output is correct |
5 | Correct | 1 ms | 724 KB | Output is correct |
6 | Correct | 0 ms | 596 KB | Output is correct |
7 | Incorrect | 1 ms | 724 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 3284 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 114 ms | 143588 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |