98282024-03-08 22:19:10SleepyOverlordFestés (50 pont)cpp17Accepted 50/50287ms65372 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define MX(x, y) x = max(x, y);
#define MN(x, y) x = min(x, y);

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

template <class T> ostream& operator <<(ostream & os, const vector<T> &vec)
{
	for (int i = 0; i < vec.size() - 1; ++i) os << vec[i] << ' ';
	return os << vec[vec.size() - 1];
}

template <class T1, class T2> ostream& operator <<(ostream & os, const pair<T1, T2> &p)
{
	return os << p.X << " " << p.Y;
}

template <typename T>
void pr(T var1)
{
	cout << var1 << '\n';
}
template <typename T, typename... Types>
void pr(T var1, Types... var2)
{
	cout << var1;
	pr(var2...);
}

const LL INF = 1e+16;

int n, m;
VI row;
vector < vector <VI> > col;

int main()
{
	#ifdef AT_HOME
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> m;
	row.RS(n + 1);
	FOR(i, 1, n) cin >> row[i];
	col.RS(m + 1, vector <VI> (n + 1, VI(n + 1)));
	FOR(i, 1, m)
		FOR(l, 1, n)
			FOR(r, l, n) cin >> col[i][l][r];

	LL sol = INF;
	FOR(rowMask, 0, (1 << n) - 1)
	{
		LL sum = 0;
		FOR(i, 1, n)
			if (rowMask & (1 << (i - 1))) sum += row[i];

		FOR(i, 1, m)
		{
			VLL dp(n + 1, INF);
			dp[0] = 0;
			FOR(j, 1, n)
			{
				if (rowMask & (1 << (j - 1))) dp[j] = dp[j - 1];
				LL mn = INF;
				FORD(l, j, 1)
				{
					MN(mn, dp[l - 1]);
					MN(dp[j], col[i][l][j] + mn);
				}
			}
			sum += dp[n];
		}

		MN(sol, sum);
	}
	pr(sol);

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2104 KiB
2Accepted0/03ms2152 KiB
3Accepted2/2158ms53856 KiB
4Accepted2/23ms2652 KiB
5Accepted3/34ms3136 KiB
6Accepted2/226ms8708 KiB
7Accepted2/2275ms64136 KiB
8Accepted2/2275ms64092 KiB
9Accepted2/2261ms64036 KiB
10Accepted2/2261ms64056 KiB
11Accepted2/2257ms63644 KiB
12Accepted2/2234ms58836 KiB
13Accepted2/2261ms58980 KiB
14Accepted2/286ms42364 KiB
15Accepted3/387ms42432 KiB
16Accepted3/3150ms55056 KiB
17Accepted2/2160ms55156 KiB
18Accepted3/3160ms55364 KiB
19Accepted2/2246ms58600 KiB
20Accepted2/2247ms61688 KiB
21Accepted2/2256ms64544 KiB
22Accepted2/2277ms65024 KiB
23Accepted2/2275ms65276 KiB
24Accepted2/2275ms65296 KiB
25Accepted2/2287ms65372 KiB