Submission #64136089


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

const int mod = 998244353;

int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}

int sub(int a, int b)
{
	return a - b >= 0 ? a - b : a - b + mod;
}

int mult(int a, int b)
{
	return (LL)a * b % mod;
}

int binpow(int a, LL n)
{
	int res = 1;
	while (n)
	{
		if (n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

template<typename T>
void updMin(T& a, T b)
{
	a = min(a, b);
}

template<typename T>
void updMax(T& a, T b)
{
	a = max(a, b);
}

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	int n;
	cin >> n;
	VI a(n), b(n);
	VI va, vb;
	int c = 0;
	unordered_map<int, int> ca, cb, cs;
	for (int& ai : a)
	{
		cin >> ai;
		if (ai == -1)
			c++;
		else
		{
			va.PB(ai);
			ca[ai]++;
		}
	}
	for (int& bi : b)
	{
		cin >> bi;
		if (bi == -1)
			c++;
		else
		{
			vb.PB(bi);
			cb[bi]++;
		}
	}
	if (c >= n)
	{
		cout << "Yes\n";
		return 0;
	}
	sort(ALL(va));
	sort(ALL(vb));
	for (auto [x, cx] : ca)
	{
		for (auto [y, cy] : cb)
		{
			cs[x + y] += min(cx, cy);
		}
	}
	vector<PII> cands;
	for (auto [z, cz] : cs)
	{
		cands.PB({cz, z});
	}
	sort(ALL(cands), greater());
	auto check = [&](int s)
	{
		int ptr = SZ(vb) - 1;
		int matched = 0;
		for (int x : va)
		{
			while (ptr >= 0 && x + vb[ptr] > s)
				ptr--;
			if (ptr >= 0 && x + vb[ptr] == s)
			{
				matched++;
				ptr--;
			}
		}
		return matched + c >= n;
	};
	FOR(i, 0, SZ(cands))
	{
		if (i % 1000 == 0 && (db)clock() / CLOCKS_PER_SEC > 4)
			break;
		int s = cands[i].S;
		if (va.back() <= s && vb.back() <= s && check(s))
		{
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

Submission Info

Submission Time
Task B - Uniform Sum
User mshcherba
Language C++ 20 (gcc 12.2)
Score 500
Code Size 2195 Byte
Status AC
Exec Time 4318 ms
Memory 238516 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 63
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 03_medium_01.txt, 03_medium_02.txt, 03_medium_03.txt, 03_medium_04.txt, 03_medium_05.txt, 04_large_01.txt, 04_large_02.txt, 04_large_03.txt, 04_large_04.txt, 04_large_05.txt, 05_max_01.txt, 05_max_02.txt, 05_max_03.txt, 05_max_04.txt, 05_max_05.txt, 05_max_06.txt, 05_max_07.txt, 05_max_08.txt, 05_max_09.txt, 05_max_10.txt, 06_all_distinct_yes_01.txt, 06_all_distinct_yes_02.txt, 06_all_distinct_yes_03.txt, 06_all_distinct_yes_04.txt, 06_all_distinct_yes_05.txt, 07_all_distinct_no_01.txt, 07_all_distinct_no_02.txt, 07_all_distinct_no_03.txt, 07_all_distinct_no_04.txt, 07_all_distinct_no_05.txt, 08_negative_killer_01.txt, 08_negative_killer_02.txt, 08_negative_killer_03.txt, 08_negative_killer_04.txt, 08_negative_killer_05.txt, 09_random_z_killer_01.txt, 09_random_z_killer_02.txt, 09_random_z_killer_03.txt, 09_random_z_killer_04.txt, 09_random_z_killer_05.txt, 09_random_z_killer_06.txt, 09_random_z_killer_07.txt, 09_random_z_killer_08.txt, 09_random_z_killer_09.txt, 09_random_z_killer_10.txt, 10_sort_z_killer_01.txt, 10_sort_z_killer_02.txt, 10_sort_z_killer_03.txt, 10_sort_z_killer_04.txt, 10_sort_z_killer_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3636 KiB
00_sample_02.txt AC 1 ms 3508 KiB
00_sample_03.txt AC 1 ms 3552 KiB
01_handmade_01.txt AC 1 ms 3540 KiB
01_handmade_02.txt AC 1 ms 3632 KiB
01_handmade_03.txt AC 1 ms 3568 KiB
01_handmade_04.txt AC 1 ms 3512 KiB
01_handmade_05.txt AC 15 ms 4000 KiB
02_small_01.txt AC 1 ms 3556 KiB
02_small_02.txt AC 1 ms 3636 KiB
02_small_03.txt AC 1 ms 3572 KiB
02_small_04.txt AC 1 ms 3544 KiB
02_small_05.txt AC 1 ms 3596 KiB
03_medium_01.txt AC 1 ms 3624 KiB
03_medium_02.txt AC 2 ms 3664 KiB
03_medium_03.txt AC 1 ms 3724 KiB
03_medium_04.txt AC 1 ms 3568 KiB
03_medium_05.txt AC 1 ms 3576 KiB
04_large_01.txt AC 13 ms 4920 KiB
04_large_02.txt AC 2 ms 3824 KiB
04_large_03.txt AC 7 ms 3756 KiB
04_large_04.txt AC 73 ms 21252 KiB
04_large_05.txt AC 104 ms 6796 KiB
05_max_01.txt AC 323 ms 55688 KiB
05_max_02.txt AC 358 ms 20896 KiB
05_max_03.txt AC 224 ms 15368 KiB
05_max_04.txt AC 5 ms 3820 KiB
05_max_05.txt AC 11 ms 6260 KiB
05_max_06.txt AC 1 ms 3712 KiB
05_max_07.txt AC 15 ms 4840 KiB
05_max_08.txt AC 154 ms 37476 KiB
05_max_09.txt AC 65 ms 20120 KiB
05_max_10.txt AC 283 ms 51640 KiB
06_all_distinct_yes_01.txt AC 2108 ms 238440 KiB
06_all_distinct_yes_02.txt AC 2166 ms 238184 KiB
06_all_distinct_yes_03.txt AC 2183 ms 237920 KiB
06_all_distinct_yes_04.txt AC 2119 ms 238460 KiB
06_all_distinct_yes_05.txt AC 2131 ms 238516 KiB
07_all_distinct_no_01.txt AC 4291 ms 235020 KiB
07_all_distinct_no_02.txt AC 4318 ms 238440 KiB
07_all_distinct_no_03.txt AC 4313 ms 238180 KiB
07_all_distinct_no_04.txt AC 4302 ms 234496 KiB
07_all_distinct_no_05.txt AC 4294 ms 238192 KiB
08_negative_killer_01.txt AC 1316 ms 55340 KiB
08_negative_killer_02.txt AC 1196 ms 55804 KiB
08_negative_killer_03.txt AC 1408 ms 55280 KiB
08_negative_killer_04.txt AC 1451 ms 51664 KiB
08_negative_killer_05.txt AC 804 ms 26644 KiB
09_random_z_killer_01.txt AC 414 ms 61668 KiB
09_random_z_killer_02.txt AC 344 ms 62068 KiB
09_random_z_killer_03.txt AC 411 ms 62020 KiB
09_random_z_killer_04.txt AC 364 ms 61748 KiB
09_random_z_killer_05.txt AC 335 ms 62020 KiB
09_random_z_killer_06.txt AC 335 ms 62072 KiB
09_random_z_killer_07.txt AC 337 ms 62012 KiB
09_random_z_killer_08.txt AC 320 ms 61752 KiB
09_random_z_killer_09.txt AC 383 ms 61652 KiB
09_random_z_killer_10.txt AC 387 ms 61672 KiB
10_sort_z_killer_01.txt AC 2117 ms 238256 KiB
10_sort_z_killer_02.txt AC 2076 ms 237196 KiB
10_sort_z_killer_03.txt AC 2167 ms 237376 KiB
10_sort_z_killer_04.txt AC 2082 ms 235808 KiB
10_sort_z_killer_05.txt AC 2170 ms 238116 KiB