답안 #212079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212079 2020-03-22T08:47:27 Z NONAME Holding (COCI20_holding) C++17
55 / 110
78 ms 102520 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 55;
const int K = 10010;
const int oo = 2e9;
int a[N], f[N][N][K], n, l, r, k, ans[N], answ[N], res = oo;

int main(){
    
    ios_base::sync_with_stdio(0); cin.tie(0);
    
//    freopen("in.txt","r",stdin);

    cin >> n >> l >> r >> k;
        
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= n + 1; j++)
            for (int kl = 0; kl <= k; kl++)
                f[i][j][kl] = oo;
        
    fill(ans, ans + n + 2, oo);
        
    f[l][l - 1][k] = 0;
    
    for (int i = l; i <= r; i++)
        f[l][l - 1][k] += a[i];
  
  	int sum = f[l][l - 1][k];
        
    for (int i = l; i > 0; i--)
        for (int j = l - 1; j <= r; j++)
            for (int ost = 0; ost <= k; ost++){
                if (f[i][j][ost] == oo) continue;
                
                ans[j] = min(ans[j], f[i][j][ost]);
                
                if (i > 0)
                    f[i - 1][j][ost] = min(f[i - 1][j][ost], f[i][j][ost]);
                
                if (j < r)
                    f[i][j + 1][ost] = min(f[i][j + 1][ost], f[i][j][ost]);
                
                if (i > 0 && j < r) {
                    int n1 = i - 1, n2 = j + 1;
                    f[n1][n2][ost - (n2 - n1)] = min(f[n1][n2][ost - (n2 - n1)], f[i][j][ost] + a[n1] - a[n2]);
                }
            }
    
    for (int i = 1; i <= r; i++)
        ans[i] = min(ans[i], ans[i - 1]);
    
    // right side
    
    fill(answ, answ + n + 2, oo);
    
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= n + 1; j++)
            for (int kl = 0; kl <= k; kl++)
                f[i][j][kl] = oo;
        
    f[r][r + 1][k] = 0;
    
    for (int i = l; i <= r; i++)
        f[r][r + 1][k] += a[i];
        
    for (int i = r; i <= n; i++)
        for (int j = r + 1; j >= l; j--)
            for (int ost = 0; ost <= k; ost++){
                if (f[i][j][ost] == oo) continue;
                
                answ[j] = min(answ[j], f[i][j][ost]);
                
                if (i < n)
                    f[i + 1][j][ost] = min(f[i + 1][j][ost], f[i][j][ost]);
                
                if (j > l)
                    f[i][j - 1][ost] = min(f[i][j - 1][ost], f[i][j][ost]);
                
                if (i < n && j > l) {
                    int n1 = i + 1, n2 = j - 1;
                    f[n1][n2][ost - (n1 - n2)] = min(f[n1][n2][ost - (n1 - n2)], f[i][j][ost] + a[n1] - a[n2]);
                }
            }
    
    for (int i = n; i >= l; i--)
        answ[i] = min(answ[i], answ[i + 1]);
        
    for (int loc = l - 1; loc <= r; loc++)
        if (ans[loc] < oo && answ[loc + 1] < oo)
            res = min(res, ans[loc] + answ[loc + 1]);
        
    cout << res - sum;
    
    return 0;
}

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:29:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = l; i <= r; i++)
     ^~~
holding.cpp:32:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    int sum = f[l][l - 1][k];
    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 10 ms 7040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 10 ms 7040 KB Output is correct
8 Correct 10 ms 11520 KB Output is correct
9 Correct 11 ms 11904 KB Output is correct
10 Correct 12 ms 12032 KB Output is correct
11 Correct 11 ms 13056 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Correct 78 ms 102520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 10 ms 7040 KB Output is correct
8 Correct 10 ms 11520 KB Output is correct
9 Correct 11 ms 11904 KB Output is correct
10 Correct 12 ms 12032 KB Output is correct
11 Correct 11 ms 13056 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Correct 78 ms 102520 KB Output is correct
14 Correct 9 ms 11008 KB Output is correct
15 Correct 10 ms 11776 KB Output is correct
16 Incorrect 10 ms 11520 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 10 ms 7040 KB Output is correct
8 Correct 10 ms 11520 KB Output is correct
9 Correct 11 ms 11904 KB Output is correct
10 Correct 12 ms 12032 KB Output is correct
11 Correct 11 ms 13056 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Correct 78 ms 102520 KB Output is correct
14 Correct 9 ms 11008 KB Output is correct
15 Correct 10 ms 11776 KB Output is correct
16 Incorrect 10 ms 11520 KB Output isn't correct
17 Halted 0 ms 0 KB -