2292021-03-05 10:49:44mraronDinamitcpp14Accepted 50/5010ms4452 KiB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

using ll = long long;
using ull = unsigned long long ;
using ld = long double ;
using str = string;
using ordered_set=tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>;


const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

const int MAXN=150;

int t[MAXN+1][MAXN+1];
int dp[MAXN+1][MAXN+1][MAXN+1]; //dp[k][i][j] -> (i,j)-ből még k-t felhasználva 
int main() {
	IO;
	int n,m,K;
	cin>>n>>m>>K;

	for(int i=0;i<n;++i) {
		for(int j=0;j<m;++j) {
			cin>>t[i][j];
			for(int k=0;k<=K;++k) dp[k][i][j]=1e9;
		}
	}

	for(int k=K;k>=0;k--) {
		for(int i=0;i<n;++i) {
			for(int j=0;j<m;++j) {
				if(i==0 && j==0) {
					dp[k][i][j]=t[i][j]>>(K-k);
				}
				
				int mx=max((i+1<n?t[i+1][j]:-1e9), (j+1<m?t[i][j+1]:-1e9));
				int akt1=(i+1<n?t[i+1][j]:-1e9), akt2=(j+1<m?t[i][j+1]:-1e9);
				for(int l=k;l>=0;l--) {
					if(i+1<n && akt1>=0) dp[l][i+1][j]=min(dp[l][i+1][j], dp[k][i][j]+akt1), akt1/=2;
					if(j+1<m && akt2>=0) dp[l][i][j+1]=min(dp[l][i][j+1], dp[k][i][j]+akt2), akt2/=2;
					if(mx==0) break ;
					mx/=2;
				}
				
				//~ if(i+1<n) {
					//~ int akt=t[i+1][j], diff=0;
					//~ while(k-diff>=0) {
						//~ dp[i+1][j][k-diff]=min(dp[i+1][j][k-diff], dp[i][j][k]+akt);
						
						//~ if(akt==0) break ;
						//~ diff++;
						//~ akt/=2;
					//~ } 
				//~ }
				
				//~ if(j+1<m) {
					//~ int akt=t[i][j+1], diff=0;
					//~ while(k-diff>=0) {
						//~ dp[i][j+1][k-diff]=min(dp[i][j+1][k-diff], dp[i][j][k]+akt);
						
						//~ if(akt==0) break ;
						//~ diff++;
						//~ akt/=2;
					//~ } 
				//~ }
				
			
			}
		}
	}

	cout<<dp[0][n-1][m-1]<<"\n";
	
	return 0;
}

SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms2000 KiB
2Accepted0/07ms4276 KiB
3Accepted2/22ms2016 KiB
4Accepted2/21ms2032 KiB
5Accepted3/31ms2048 KiB
6Accepted3/31ms2056 KiB
7Accepted2/26ms4292 KiB
8Accepted3/36ms4324 KiB
9Accepted2/21ms2824 KiB
10Accepted2/22ms2820 KiB
11Accepted3/32ms2824 KiB
12Accepted3/32ms2832 KiB
13Accepted2/24ms3344 KiB
14Accepted3/32ms3348 KiB
15Accepted2/27ms4368 KiB
16Accepted3/37ms4380 KiB
17Accepted2/27ms4392 KiB
18Accepted3/37ms4404 KiB
19Accepted2/27ms4412 KiB
20Accepted3/37ms4428 KiB
21Accepted2/27ms4440 KiB
22Accepted3/310ms4452 KiB