답안 #477975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477975 2021-10-04T20:50:44 Z mychecksedad Holding (COCI20_holding) C++17
88 / 110
95 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];
vector<vector<vector<int>>> dp;
void solve(){
    cin >> n >> l >> r >> k;
    dp.resize(n + 1);
    for(int i = 0; i <= n; ++i){
        dp[i].resize(n + 1);
        for(int j = 0; j <= n; ++j) dp[i][j].resize(k+1);
    }
    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:40: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]
   40 |     for(int i = 1; i <= a.size(); ++i){
      |                    ~~^~~~~~~~~~~
holding.cpp:41: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]
   41 |         for(int j = 1; j <= b.size(); ++j){
      |                        ~~^~~~~~~~~~~
holding.cpp: In function 'int main()':
holding.cpp:61:16: warning: unused variable 'aa' [-Wunused-variable]
   61 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 6 ms 6860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 6 ms 6860 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 88 ms 102128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 6 ms 6860 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 88 ms 102128 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 844 KB Output is correct
17 Correct 2 ms 1996 KB Output is correct
18 Correct 3 ms 2892 KB Output is correct
19 Correct 87 ms 102072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 6 ms 6860 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 88 ms 102128 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 844 KB Output is correct
17 Correct 2 ms 1996 KB Output is correct
18 Correct 3 ms 2892 KB Output is correct
19 Correct 87 ms 102072 KB Output is correct
20 Correct 12 ms 16676 KB Output is correct
21 Correct 17 ms 26512 KB Output is correct
22 Correct 2 ms 2124 KB Output is correct
23 Correct 95 ms 149828 KB Output is correct
24 Correct 11 ms 12748 KB Output is correct
25 Runtime error 95 ms 262148 KB Execution killed with signal 9