2902021-07-18 20:25:59Szin AttilaDinamitcpp14Wrong answer 23/504ms2344 KiB
#include <bits/stdc++.h>
using namespace std;

void printq(priority_queue<int> q)
{
  cout << "queue: ";
  while(!q.empty()){
    cout << q.top() << " ";
    q.pop();
  }
  cout << "\n";
}

int main() {
	int n,m,k;
  cin >> n >> m >> k;
  
  vector<vector<int> > tabla, dp(n+1, vector<int>(m, 0));
  priority_queue<int> mo;
  
  for(int i = 0; i < n; i++) {
    vector<int> v;
    for(int j = 0; j < m; j++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    tabla.push_back(v);
  }
  
  dp[0][0] = tabla[0][0];
  
  for(int i = 1; i < n; i++) {
    dp[i][0] = tabla[i][0] + dp[i-1][0];
  }
  for(int i = 1; i < m; i++) {
    dp[0][i] = tabla[0][i] + dp[0][i-1];
  }
  
  for(int i = 1; i < n; i++) {
    for(int j = 1; j < m; j++) {
      dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + tabla[i][j];
    }
  }
  
  /*cout << "dp: " << "\n";
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cout << dp[i][j] << " ";
    }
    cout << "\n";
  }*/
  
  int i = n-1, j = m-1;
  while(i > 0 || j > 0)
  {
    //cout << "i: " << i << " j: " << j << " \n";
    mo.push(tabla[i][j]);
    if(i == 0) {
      j--;
    }
    else if(j == 0) {
      i--;
    }
    else {
      if(dp[i-1][j] < dp[i][j-1]) {
        i--;
      }
      else {
        j--;
      }
    }
  }
  mo.push(tabla[i][j]);
  
  //printq(mo);
  while(k--) {
    int curr = mo.top();
    mo.pop();
    
    mo.push(curr/2);
  }
  //printq(mo);
  
  int ki = 0;
  while(!mo.empty()) 
  {
    ki += mo.top();
    mo.pop();
  }
  cout << ki << "\n";
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/04ms1988 KiB
2Wrong answer0/02ms2100 KiB
3Accepted2/22ms2144 KiB
4Accepted2/22ms2164 KiB
5Accepted3/32ms2172 KiB
6Accepted3/32ms2184 KiB
7Accepted2/22ms2200 KiB
8Accepted3/32ms2212 KiB
9Wrong answer0/21ms2216 KiB
10Accepted2/21ms2216 KiB
11Accepted3/31ms2224 KiB
12Wrong answer0/31ms2224 KiB
13Wrong answer0/21ms2232 KiB
14Accepted3/31ms2240 KiB
15Wrong answer0/22ms2256 KiB
16Wrong answer0/32ms2268 KiB
17Wrong answer0/22ms2276 KiB
18Wrong answer0/32ms2292 KiB
19Wrong answer0/22ms2300 KiB
20Wrong answer0/32ms2316 KiB
21Wrong answer0/22ms2332 KiB
22Wrong answer0/32ms2344 KiB