답안 #584865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584865 2022-06-28T05:40:15 Z 박상훈(#8379) 도장 모으기 (JOI14_stamps) C++14
85 / 100
1000 ms 1912 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
ll dp[3030][3030], cstS[3030], dcstS[3030], UD[3030], DU[3030], T;

ll cst(int l, int r){
    if (r<l) return 0;
    return cstS[r] - cstS[l-1];
}

ll dcst(int l, int r){
    if (r<l) return 0;
    return cstS[r] - cstS[l-1] - (dcstS[r] - dcstS[l-1]);
}

ll Tij(int r, int l){
    return T*(r-l)*2 + UD[r] + DU[l];
}

int main(){
    int n;
    scanf("%d %lld", &n, &T);
    for (int i=1;i<=n;i++){
        int u, v, d, e;
        scanf("%d %d %d %d", &u, &v, &d, &e);
        UD[i] = u + e;
        DU[i] = d + v;
        int uu = u+v, dd = d+e;
        cstS[i] = cstS[i-1] + uu;
        dcstS[i] = dcstS[i-1] + max(uu-dd, 0);
    }

    ll ans = T*(n+1) + cst(1, n);

    for (int i=1;i<=n;i++){
        for (int j=1;j<i;j++){
            dp[i][j] = T*i + cst(1, j-1) + dcst(j+1, i-1) + Tij(i, j);

            for (int k=1;k<=j;k++){
                for (int l=1;l<k;l++){
                    ///case 1. k<=j
                    dp[i][j] = min(dp[i][j], dp[k][l] + T*(i-k) + cst(k+1, j-1) + dcst(j+1, i-1) + Tij(i, j));
                }
            }

            for (int k=j+1;k<=i;k++){
                for (int l=1;l<j;l++){
                    ///case 2. k>j, l<j
                    dp[i][j] = min(dp[i][j], dp[k][l] + T*(i-k) + dcst(k+1, i-1) + Tij(i, j) - dcst(j, j));
                }

                if (k==i) break;
                ///case 3.k>j, l=j
                int l = j;
                dp[i][j] = min(dp[i][j], dp[k][l] + T*(i-k) + dcst(k+1, i-1) + Tij(i, j));
            }

            ans = min(ans, dp[i][j] + T*(n+1-i) + cst(i+1, n));
        }
    }

    //printf("%lld\n", dp[2][1]);
    printf("%lld\n", ans);
    return 0;
}

Compilation message

stamps.cpp: In function 'int main()':
stamps.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     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("%d %d %d %d", &u, &v, &d, &e);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 720 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 15 ms 724 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 11 ms 596 KB Output is correct
8 Correct 23 ms 624 KB Output is correct
9 Correct 19 ms 688 KB Output is correct
10 Correct 15 ms 724 KB Output is correct
11 Correct 16 ms 684 KB Output is correct
12 Correct 15 ms 688 KB Output is correct
13 Correct 24 ms 716 KB Output is correct
14 Correct 24 ms 724 KB Output is correct
15 Correct 17 ms 724 KB Output is correct
16 Correct 17 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 1912 KB Time limit exceeded
2 Halted 0 ms 0 KB -