답안 #477974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477974 2021-10-04T20:47:17 Z mychecksedad Holding (COCI20_holding) C++17
88 / 110
114 ms 262148 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
const int N = 1e4+15, M = 110, F = 2147483646, K = 20;



int n, l, r, k, arr[M], dp[M][M][N];
void solve(){
    cin >> n >> l >> r >> k;
    for(int i = 1; i <= n; ++i) cin >> arr[i];
    int sum = 0;
    for(int i = l; i <= r; ++i) sum += arr[i];
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= n; ++j){
            for(int l = 0; l <= k; ++l) dp[i][j][l] = sum;
        }
    }
    vector<pair<int, int>> a;
    vector<pair<int, int>> b;
    for(int i = 1; i <= n; ++i){
        if(i < l || i > r) a.pb({arr[i], i});
        else b.pb({arr[i], i});
    }
    int ans = sum;
    for(int i = 1; i <= a.size(); ++i){
        for(int j = 1; j <= b.size(); ++j){
            int dist = abs(a[i - 1].second - b[j - 1].second);
            for(int l = 0; l <= k; ++l){
                dp[i][j][l] = min({dp[i - 1][j][l], dp[i][j - 1][l], (l > 0 ? dp[i][j][l - 1] : F)});
                if(l >= dist){
                    // cout << i << ' ' << j  << ' ' << l << ' ' << dp[i][j][l] << ' ' << (a[i - 1].first - b[j - 1].first) << '\n';   
                    dp[i][j][l] = min(dp[i][j][l], dp[i - 1][j - 1][l - dist] + (a[i - 1].first - b[j - 1].first));
                }
                // 
                ans = min(ans, dp[i][j][l]);
            }
        }
    }
    cout << ans;
}



int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
    }
    return 0;
 
}

Compilation message

holding.cpp: In function 'void solve()':
holding.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 1; i <= a.size(); ++i){
      |                    ~~^~~~~~~~~~~
holding.cpp:35:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int j = 1; j <= b.size(); ++j){
      |                        ~~^~~~~~~~~~~
holding.cpp: In function 'int main()':
holding.cpp:55:16: warning: unused variable 'aa' [-Wunused-variable]
   55 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 5 ms 6988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 5 ms 6988 KB Output is correct
8 Correct 5 ms 11596 KB Output is correct
9 Correct 5 ms 11852 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 5 ms 13004 KB Output is correct
12 Correct 5 ms 11980 KB Output is correct
13 Correct 73 ms 102556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 5 ms 6988 KB Output is correct
8 Correct 5 ms 11596 KB Output is correct
9 Correct 5 ms 11852 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 5 ms 13004 KB Output is correct
12 Correct 5 ms 11980 KB Output is correct
13 Correct 73 ms 102556 KB Output is correct
14 Correct 5 ms 11040 KB Output is correct
15 Correct 5 ms 11852 KB Output is correct
16 Correct 4 ms 11468 KB Output is correct
17 Correct 5 ms 12620 KB Output is correct
18 Correct 8 ms 13516 KB Output is correct
19 Correct 69 ms 102692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 5 ms 6988 KB Output is correct
8 Correct 5 ms 11596 KB Output is correct
9 Correct 5 ms 11852 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 5 ms 13004 KB Output is correct
12 Correct 5 ms 11980 KB Output is correct
13 Correct 73 ms 102556 KB Output is correct
14 Correct 5 ms 11040 KB Output is correct
15 Correct 5 ms 11852 KB Output is correct
16 Correct 4 ms 11468 KB Output is correct
17 Correct 5 ms 12620 KB Output is correct
18 Correct 8 ms 13516 KB Output is correct
19 Correct 69 ms 102692 KB Output is correct
20 Correct 24 ms 57916 KB Output is correct
21 Correct 28 ms 67736 KB Output is correct
22 Correct 16 ms 43340 KB Output is correct
23 Correct 90 ms 190828 KB Output is correct
24 Correct 23 ms 54036 KB Output is correct
25 Runtime error 114 ms 262148 KB Execution killed with signal 9