Submission #944612

# Submission time Handle Problem Language Result Execution time Memory
944612 2024-03-13T01:49:20 Z anudari_t Dominance (CEOI08_dominance) C++17
100 / 100
10 ms 612 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<lint, lint>;
const int MAXN = 6005;

struct rect{
	int sx, ex, sy, ey, v;
};

struct event{
	int s, e, x, y;
};

int n;

pi solve(vector<rect> v){
	vector<int> vx, vy;
	for(auto &i : v){
		vy.push_back(i.sy);
		vy.push_back(i.ey + 1);
	}
	sort(vy.begin(), vy.end());
	vy.resize(unique(vy.begin(), vy.end()) - vy.begin());
	vector<event> ev;
	for(auto &i : v){
		ev.push_back({i.sy, i.ey + 1, i.sx, +i.v});
		ev.push_back({i.sy, i.ey + 1, i.ex + 1, -i.v});
	}
	sort(ev.begin(), ev.end(), [&](const event &x, const event &y){
		return x.x < y.x;
	});
	int arr[MAXN] = {};
	pi dap(0, 0);
	for(int i=0; i+1<ev.size(); i++){
		int s = lower_bound(vy.begin(), vy.end(), ev[i].s) - vy.begin();
		int e = lower_bound(vy.begin(), vy.end(), ev[i].e) - vy.begin();
		for(int j=s; j<e; j++){
			arr[j] += ev[i].y;
		}
		for(int j=0; j<vy.size()-1; j++){
			if(arr[j] > 0){
				dap.first += 1ll * (vy[j + 1] - vy[j]) * (ev[i + 1].x - ev[i].x);
			}
			if(arr[j] < 0){
				dap.second += 1ll * (vy[j + 1] - vy[j]) * (ev[i + 1].x - ev[i].x);
			}
		}
	}
	return dap;
}

vector<rect> v[2];

void AddRect(int sx, int ex, int sy, int ey, char c, int p){
	auto D = [&](int p){
		if(p < 0) return (p - 1) / 2;
		return p / 2;
	};
	if(p < 0) p = 1;
	sx = D(sx); ex = D(ex); sy = D(sy); ey = D(ey);
	v[p].push_back({sx, ex, sy, ey, c == 'W' ? 1 : -1});
}

int main(){
	scanf("%*d %*d %d",&n);
	for(int i=0; i<n; i++){
		int x, y, r;
		char c[3];
		cin >> c >> x >> y >> r;
		int sx = x - y - r, ex = x - y + r;
		int sy = x + y - r, ey = x + y + r;
		AddRect(sx, ex, sy, ey, *c, (x + y - r) % 2);
		AddRect(sx + 1, ex - 1, sy + 1, ey - 1, *c, (x + y - r + 1) % 2);
	}
	auto p1 = solve(v[0]);
	auto p2 = solve(v[1]);
	printf("%lld %lld\n", p1.first + p2.first, p1.second + p2.second);
}

Compilation message

dominance.cpp: In function 'pi solve(std::vector<rect>)':
dominance.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i=0; i+1<ev.size(); i++){
      |               ~~~^~~~~~~~~~
dominance.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int j=0; j<vy.size()-1; j++){
      |                ~^~~~~~~~~~~~
dominance.cpp: In function 'int main()':
dominance.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  scanf("%*d %*d %d",&n);
      |  ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 7 ms 604 KB Output is correct
5 Correct 7 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 8 ms 456 KB Output is correct
10 Correct 9 ms 452 KB Output is correct
11 Correct 10 ms 612 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 9 ms 532 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 8 ms 604 KB Output is correct
16 Correct 6 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct