44802023-03-28 13:13:57semmiDinamitcpp17Wrong answer 23/503ms4220 KiB
#include <bits/stdc++.h>

using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<vector<int>> oszlop(a+1, vector<int>(b+1)), // saving the rows and columns
    dp(a+1, vector<int>(b+1,INT_MAX)), backtrack(a+1, vector<int>(b+1)); // backtrack saves the shortest path
    
    for(int i = 1;i<=a;i++ ) {
        for(int z = 1;z<=b;z++ ) {
            cin >> oszlop[i][z];
        }
    } // saving all the data



    dp[1][1] = oszlop[1][1]; // default dp initialization

    backtrack[1][1] = -1; // means it is the end of the road

    for(int i = 2;i<=b;i++ ) {
        dp[1][i] = dp[1][i-1] + oszlop[1][i];
        backtrack[1][i] = 1;
    }

    for(int i = 2;i<=a;i++ ) {
        dp[i][1] = dp[i-1][1] + oszlop[i][1];
        backtrack[i][1] = 0;
    }
    
    // pre initialization 

    // 1 ha balra kulonben 0 ha felfele
    for(int i = 2;i<=a;i++ ) {
        for(int z = 2;z<=b;z++ ) {
            dp[i][z] = min(dp[i-1][z], dp[i][z-1]) + oszlop[i][z];
            if(dp[i-1][z] > dp[i][z-1]) backtrack[i][z] = 1;
            else backtrack[i][z]= 0;
        }
    }
    vector<int> visszafejt;
    vector<int> ans;
    int x = a, y = b;
    while(backtrack[x][y] != -1) {
        ans.push_back(oszlop[x][y]);
        if(backtrack[x][y] == 0) {
            x--;
        } else {
            y--;
        }
    }
    ans.push_back(oszlop[1][1]);
    reverse(ans.begin(), ans.end());
    
    //cout << dp[a][b] << endl;
    int ansf= dp[a][b];
    for(int i = 0;i < c;i++ ) {
        sort(ans.begin(), ans.end());
        int temp = ans[ans.size()-1]/2;
        ansf -= ans[ans.size()-1] - temp;
        ans[ans.size()-1]/=2;
    }
    cout << ansf << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/03ms1816 KiB
2Wrong answer0/03ms2028 KiB
3Accepted2/23ms2236 KiB
4Accepted2/23ms2448 KiB
5Accepted3/33ms2676 KiB
6Accepted3/33ms2876 KiB
7Accepted2/23ms2960 KiB
8Accepted3/33ms3092 KiB
9Wrong answer0/22ms3152 KiB
10Accepted2/23ms3152 KiB
11Accepted3/33ms3392 KiB
12Wrong answer0/33ms3364 KiB
13Wrong answer0/23ms3396 KiB
14Accepted3/33ms3480 KiB
15Wrong answer0/23ms3612 KiB
16Wrong answer0/33ms3980 KiB
17Wrong answer0/23ms4212 KiB
18Wrong answer0/33ms4220 KiB
19Wrong answer0/23ms4216 KiB
20Wrong answer0/33ms4080 KiB
21Wrong answer0/23ms4180 KiB
22Wrong answer0/33ms4180 KiB