98052024-03-07 01:02:26SleepyOverlordDarabolás (50 pont)cpp17Időlimit túllépés 12/50300ms3836 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...);
}

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});
	}
}

int n, m, sol = 0;
VI row, col;

void solve(int lx, int ly, int rx, int ry)
{
	if (lx + 1 == rx and ly + 1 == ry) return;
	int mi = 0;
	FOR(i, lx + 1, rx - 1)
		if (row[i] > row[mi]) mi = i;
	int mi2 = 0;
	FOR(i, ly + 1, ry - 1)
		if (col[i] > col[mi2]) mi2 = i;
	if (row[mi] > col[mi2])
	{
		sol += row[mi];
		solve(lx, ly, mi, ry);
		solve(mi, ly, rx, ry);
	}
	else
	{
		sol += col[mi2];
		solve(lx, ly, rx, mi2);
		solve(lx, mi2, rx, ry);
	}
}

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

	cin >> n >> m;
	row.RS(n), col.RS(m);
	FOR(i, 1, n - 1) cin >> row[i];
	FOR(i, 1, m - 1) cin >> col[i];

	solve(0, 0, n, m);
	pr(sol);

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base12/50
1Elfogadva0/03ms1880 KiB
2Időlimit túllépés0/0300ms1780 KiB
3Elfogadva1/113ms2388 KiB
4Elfogadva1/176ms2500 KiB
5Időlimit túllépés0/1273ms2608 KiB
6Időlimit túllépés0/1273ms2780 KiB
7Elfogadva1/14ms3040 KiB
8Elfogadva1/112ms2960 KiB
9Elfogadva1/176ms2968 KiB
10Elfogadva1/113ms2964 KiB
11Elfogadva1/176ms3088 KiB
12Elfogadva1/113ms3172 KiB
13Elfogadva1/13ms3288 KiB
14Elfogadva1/114ms3416 KiB
15Elfogadva1/113ms3544 KiB
16Elfogadva1/117ms3552 KiB
17Hibás válasz0/129ms3536 KiB
18Hibás válasz0/128ms3536 KiB
19Hibás válasz0/229ms3532 KiB
20Hibás válasz0/230ms3532 KiB
21Időlimit túllépés0/3300ms3524 KiB
22Időlimit túllépés0/3245ms3800 KiB
23Időlimit túllépés0/4280ms3836 KiB
24Időlimit túllépés0/4256ms2876 KiB
25Időlimit túllépés0/4252ms3128 KiB
26Időlimit túllépés0/4264ms3108 KiB
27Időlimit túllépés0/4256ms3444 KiB
28Időlimit túllépés0/4284ms3448 KiB