95072024-02-22 12:47:251478Festés (50 pont)cpp17Wrong answer 17/50453ms125940 KiB
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
ll MOD = 1e9 + 7;

int N_MAX = 4;
int M_MAX = 1e5;
int n, m;

vector<int> r(N_MAX + 1);
vector<vector<vector<int>>> c(M_MAX + 1, vector<vector<int>>(N_MAX + 1, vector<int>(N_MAX + 1))); 

vector<vector<vector<int>>> dpCol(M_MAX + 1, vector<vector<int>>(N_MAX + 1, vector<int>(N_MAX + 1))); 

int main()
{
	//ifstream cin("in.txt");
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> r[i];
	}

	for(int j = 1; j <= m; j++){
		for(int u = 1; u <= n; u++){
			for(int d = u; d <= n; d++){
				
				cin >> c[j][u][d];
				
			}
		}
	}


	for(int j = 1; j <= m; j++){
		//cout << j << ": " << '\n';
		for(int d = 1; d <= n; d++){
			for(int u = d; u >= 1; u--){	
				dpCol[j][u][d] = c[j][u][d];
				if(u == d) 
				{
					continue;
				}

				for(int d2 = u; d2 <= d - 1; d2++){
					//cout << "[" << u << ", " << d2 << "] " << "[" << d2 + 1 << ", " << d << "]" << '\n';
					dpCol[j][u][d] = min(dpCol[j][u][d], dpCol[j][u][d2] + dpCol[j][d2 + 1][d]);
				}
			}
		}
	}


	for(int j = 1; j <= m; j++){
		for(int u = 1; u <= n; u++){
			for(int d = n; d >= u; d--){
				if(u - 1 >= 1){
					dpCol[j][u][d] = min(dpCol[j][u][d], dpCol[j][u - 1][d]);
				}
				if(d + 1 <= n){
					dpCol[j][u][d] = min(dpCol[j][u][d], dpCol[j][u][d + 1]);
				}
			}
		}
	}

	/*for(int j = 1; j <= m; j++){
		cout << j << ": " << '\n';
		for(int u = 1; u <= n; u++){
			for(int d = 1; d <= n; d++){
				cout << dpCol[j][u][d] << " ";
			}
			cout << '\n';
		}
		cout << '\n';
	}*/




	int s = 0;

	vector<ll> sum(n + 1);
	vector<int> dpRow(n + 1);

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			sum[i] += dpCol[j][s + 1][i];
		}
		if(sum[i] < r[i] + dpRow[i - 1]){
			dpRow[i] = sum[i] + dpRow[s];
		}
		else{
			s = i;
			dpRow[i] = r[i] + dpRow[i - 1];
		}

		//cout << i << " " << s << " " <<  sum[i] << " " << dpRow[i] << '\n';
	}

	cout << dpRow[n];




	
	




}
SubtaskSumTestVerdictTimeMemory
base17/50
1Accepted0/0107ms123584 KiB
2Wrong answer0/0104ms123812 KiB
3Wrong answer0/2324ms124152 KiB
4Wrong answer0/2108ms123952 KiB
5Wrong answer0/3109ms124344 KiB
6Wrong answer0/2130ms124368 KiB
7Accepted2/2428ms124592 KiB
8Wrong answer0/2421ms124744 KiB
9Wrong answer0/2407ms124676 KiB
10Wrong answer0/2405ms124844 KiB
11Wrong answer0/2402ms124924 KiB
12Wrong answer0/2379ms124928 KiB
13Wrong answer0/2400ms125084 KiB
14Accepted2/2209ms124940 KiB
15Accepted3/3231ms125064 KiB
16Accepted3/3305ms125276 KiB
17Accepted2/2305ms125492 KiB
18Accepted3/3301ms125620 KiB
19Accepted2/2372ms125704 KiB
20Wrong answer0/2398ms125832 KiB
21Wrong answer0/2418ms125836 KiB
22Wrong answer0/2398ms125940 KiB
23Wrong answer0/2400ms125936 KiB
24Wrong answer0/2411ms125932 KiB
25Wrong answer0/2453ms125932 KiB