86542024-01-25 00:09:11SleepyOverlordFestés (50 pont)cpp17Időlimit túllépés 7/50699ms14704 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 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...);
}

void in(int &n, VI &a) //array of ints
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VS &a) //array of strings
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VPII &a) //array of pairs
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i].X >> a[i].Y;
}

void in(int &n, int &m, VVI &g) //unweighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, VVI &g) //unweighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, int &m, vector <VPII> &g) //weighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

void in(int &n, vector <VPII> &g) //weighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

const int INF = 1e+16;

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

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

	cin >> n >> m;
	row.RS(n + 1);
	FOR(i, 1, n) cin >> row[i];
	int PAIRS = n * (n + 1) / 2;
	col.reserve(m * PAIRS);
	FOR(i, 1, m)
	{
		int l = 1, r = 1;
		FOR(j, 1, PAIRS)
		{
			int x;
			cin >> x;
			col.PB({l, r, x});
			++r;
			if (r == n + 1) ++l, r = l;
		}
	}

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

		FOR(i, 1, m)
		{
			LL best = INF;
			FOR(msk, 0, (1 << PAIRS) - 1)
			{
				int covered = rowMask;
				LL sum2 = 0;
				FOR(j, 0, PAIRS - 1)
					if (msk & (1 << j))
					{
						auto [l, r, cost] = col[startInd + j];
						sum2 += cost;
						FOR(k, l - 1, r - 1) covered |= (1 << k);
					}
				if (covered == (1 << n) - 1) best = min(best, sum2);
			}
			sum += best;
			startInd += PAIRS;
		}
		sol = min(sol, sum);
	}
	pr(sol);

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base7/50
1Elfogadva0/03ms1876 KiB
2Elfogadva0/017ms2124 KiB
3Időlimit túllépés0/2699ms8536 KiB
4Elfogadva2/2153ms2504 KiB
5Időlimit túllépés0/3662ms2656 KiB
6Időlimit túllépés0/2669ms3080 KiB
7Időlimit túllépés0/2657ms14072 KiB
8Időlimit túllépés0/2666ms13940 KiB
9Időlimit túllépés0/2670ms14072 KiB
10Időlimit túllépés0/2606ms14276 KiB
11Időlimit túllépés0/2662ms14292 KiB
12Időlimit túllépés0/2685ms13576 KiB
13Időlimit túllépés0/2666ms13684 KiB
14Elfogadva2/2131ms10732 KiB
15Elfogadva3/3135ms10572 KiB
16Időlimit túllépés0/3671ms9724 KiB
17Időlimit túllépés0/2677ms9896 KiB
18Időlimit túllépés0/3657ms10000 KiB
19Időlimit túllépés0/2657ms13284 KiB
20Időlimit túllépés0/2666ms13924 KiB
21Időlimit túllépés0/2681ms14372 KiB
22Időlimit túllépés0/2614ms14512 KiB
23Időlimit túllépés0/2674ms14652 KiB
24Időlimit túllépés0/2670ms14480 KiB
25Időlimit túllépés0/2666ms14704 KiB