151512025-02-14 09:19:16RRoliDinamitcpp17Wrong answer 18/506ms1012 KiB
#include <bits/stdc++.h>
using namespace std;

struct Bencu {
    int ert;
    int norm;
    vector<int> robb;
} b[40][40];

int n, m, k, a[40][40];

void beilleszt(int t, vector<int> &r) {
    while(r.size() < k || t > r[0]) {
        if(r.size() == k) r[0] = t;
        else r.push_back(t);
        sort(r.begin(), r.end());
        t /= 2;
    }
}

int main() {
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> a[i][j];
    
    b[0][0].norm = a[0][0];
    beilleszt(a[0][0], b[0][0].robb);
    int s = 0;
    for(auto i : b[0][0].robb) s += (i-i/2);
    b[0][0].ert = b[0][0].norm - s;
    
    for(int i = 1; i < n; i++) {
        b[i][0].norm = b[i-1][0].norm + a[i][0];
        for(auto l : b[i-1][0].robb) b[i][0].robb.push_back(l);
        beilleszt(a[i][0], b[i][0].robb);
        s = 0;
        for(auto l : b[i][0].robb) s += (l-l/2);
        b[i][0].ert = b[i][0].norm - s;
    }
    for(int i = 1; i < m; i++) {
        b[0][i].norm = b[0][i-1].norm + a[0][i];
        for(auto l : b[0][i-1].robb) b[0][i].robb.push_back(l);
        beilleszt(a[0][i], b[0][i].robb);
        s = 0;
        for(auto l : b[0][i].robb) s += (l-l/2);
        b[0][i].ert = b[0][i].norm - s;
    }

    for(int i = 1; i < n; i++)
        for(int j = 1; j < m; j++) {
            int ert1, ert2, norm1, norm2;
            vector<int> v1, v2;

            norm1 = b[i-1][j].norm + a[i][j];
            for(auto l : b[i-1][j].robb) v1.push_back(l);
            beilleszt(a[i][j], v1);
            s = 0;
            for(auto l : v1) s += (l-l/2);
            ert1 = norm1 - s;

            norm2 = b[i][j-1].norm + a[i][j];
            for(auto l : b[i][j-1].robb) v2.push_back(l);
            beilleszt(a[i][j], v2);
            s = 0;
            for(auto l : v2) s += (l-l/2);
            ert2 = norm2 - s;

            if(ert1 <= ert2) {
                b[i][j].norm = norm1;
                b[i][j].ert = ert1;
                for(auto l : v1) b[i][j].robb.push_back(l);
            } else {
                b[i][j].norm = norm2;
                b[i][j].ert = ert2;
                for(auto l : v2) b[i][j].robb.push_back(l);
            }
        }
    
    cout << b[n-1][m-1].ert;

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/50
1Accepted0/01ms316 KiB
2Wrong answer0/04ms820 KiB
3Runtime error0/22ms316 KiB
4Runtime error0/22ms316 KiB
5Runtime error0/32ms316 KiB
6Runtime error0/31ms316 KiB
7Accepted2/26ms820 KiB
8Accepted3/36ms832 KiB
9Wrong answer0/21ms332 KiB
10Accepted2/21ms316 KiB
11Accepted3/31ms316 KiB
12Wrong answer0/31ms460 KiB
13Wrong answer0/22ms532 KiB
14Wrong answer0/32ms516 KiB
15Wrong answer0/24ms720 KiB
16Wrong answer0/34ms708 KiB
17Accepted2/24ms872 KiB
18Accepted3/34ms820 KiB
19Wrong answer0/24ms708 KiB
20Wrong answer0/34ms1012 KiB
21Wrong answer0/24ms716 KiB
22Accepted3/34ms836 KiB