Submission #1074307

# Submission time Handle Problem Language Result Execution time Memory
1074307 2024-08-25T09:38:36 Z Joshua_Andersson Teams (IOI15_teams) C++14
0 / 100
4000 ms 20232 KB
#include "teams.h"

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

typedef long long ll;
const ll linf = ll(1e18);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;

#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())
#define all(x) begin(x),end(x)

#if _LOCAL
#define assert(x) if (!(x)) __debugbreak()
#endif

int n;
vi a;
vi b;
typedef pair<double, int> pt;
vector<p2> pts;

void init(int N, int A[], int B[])
{
	n = N;
	a.resize(N);
	b.resize(N);
	rep(i, N) a[i] = A[i], b[i] = B[i];

	rep(i, n)
	{
		pts.emplace_back(a[i], b[i]);
	}
	sort(all(pts), [](p2 a, p2 b)
		{
			return a.second < b.second;
		});
}

int rectangle_sum(int xlo, int xhi, int ylo, int yhi)
{
	int ret = 0;

	repp(i, ylo, yhi+1)
	{
		ret += pts[i].first >= xlo && pts[i].first <= xhi;
	}

	return ret;
}

typedef tuple<int, int, int> p3;
int sum(vector<p2>& hull, int xhi, int ylo, int yhi)
{
	int prev = -1;
	int taken = 0;
	repe(p, hull)
	{

		taken += rectangle_sum(prev + 1, min(p.first, xhi), 0, p.second);
		if (p.first >= xhi) break;
		prev = p.first;
	}
	return rectangle_sum(0, xhi, 0, yhi)-taken;
}

bool dominates(p2 a, p2 b)
{
	return a.first >= b.first && a.second >= b.second;
}

const int inf = int(2e9);
int can(int m, int K[]) {
	//cout << rectangle_sum(1, 3, 1, 3);
	vi k(m);
	rep(i, m) k[i] = K[i];

	sort(all(k));

	vector<p2> taken_hull;
	auto insert = [&](p2 new_corner)
	{
		bool good = 1;
		repe(p, taken_hull) if (dominates(p, new_corner)) good = 0;
		if (good)
		{
			auto it = taken_hull.begin();
			while (it != taken_hull.end())
			{
				if (dominates(new_corner, *it))
				{
					it = taken_hull.erase(it);
				}
				else it = next(it);
			}
			taken_hull.push_back(new_corner);
		}
		sort(all(taken_hull));
	};
	int lo = 0;
	rep(i, m)
	{
		while (lo < sz(pts) && pts[lo].second < k[i])
		{
			insert(p2(inf, lo));
			lo++;
		}
		if (sum(taken_hull, k[i], 0, n-1)<k[i])
		{
			return 0;
		}
		int lob = lo-1;
		int hib = n;
		while (lob+1<hib)
		{
			int mid = (lob + hib) / 2;
			if (sum(taken_hull, k[i], lo, mid) < k[i])
			{
				lob = mid;
			}
			else hib = mid;
		}
		p2 new_corner = p2(k[i], hib);
		insert(new_corner);
	}

	return 1;
}

Compilation message

teams.cpp: In lambda function:
teams.cpp:40:29: warning: declaration of 'b' shadows a global declaration [-Wshadow]
   40 |  sort(all(pts), [](p2 a, p2 b)
      |                          ~~~^
teams.cpp:25:4: note: shadowed declaration is here
   25 | vi b;
      |    ^
teams.cpp:40:23: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   40 |  sort(all(pts), [](p2 a, p2 b)
      |                    ~~~^
teams.cpp:24:4: note: shadowed declaration is here
   24 | vi a;
      |    ^
teams.cpp: In function 'int sum(std::vector<std::pair<int, int> >&, int, int, int)':
teams.cpp:59:40: warning: unused parameter 'ylo' [-Wunused-parameter]
   59 | int sum(vector<p2>& hull, int xhi, int ylo, int yhi)
      |                                    ~~~~^~~
teams.cpp: In function 'bool dominates(p2, p2)':
teams.cpp:73:25: warning: declaration of 'b' shadows a global declaration [-Wshadow]
   73 | bool dominates(p2 a, p2 b)
      |                      ~~~^
teams.cpp:25:4: note: shadowed declaration is here
   25 | vi b;
      |    ^
teams.cpp:73:19: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   73 | bool dominates(p2 a, p2 b)
      |                ~~~^
teams.cpp:24:4: note: shadowed declaration is here
   24 | vi a;
      |    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 3 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4120 KB Output is correct
2 Correct 13 ms 4308 KB Output is correct
3 Correct 13 ms 4308 KB Output is correct
4 Correct 15 ms 4804 KB Output is correct
5 Correct 405 ms 3796 KB Output is correct
6 Correct 227 ms 3792 KB Output is correct
7 Correct 9 ms 3792 KB Output is correct
8 Correct 9 ms 3796 KB Output is correct
9 Execution timed out 4086 ms 3976 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 260 ms 4560 KB Output is correct
2 Correct 495 ms 4564 KB Output is correct
3 Execution timed out 4062 ms 4564 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2535 ms 20232 KB Output is correct
2 Correct 3213 ms 20224 KB Output is correct
3 Execution timed out 4019 ms 19136 KB Time limit exceeded
4 Halted 0 ms 0 KB -