Submission #131037

# Submission time Handle Problem Language Result Execution time Memory
131037 2019-07-16T11:52:05 Z imyujin Bodyguards (CEOI10_bodyguards) C++14
Compilation error
0 ms 0 KB
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define MAXR 200005
#define fi first
#define se second

typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

vector<pll> rv, cv;

int main() {
	int R, C;

	scanf("%d", &R);
	rv.resize(R);
	for(int i = 0; i < R; i++) scanf("%lld%lld", &rv[i].fi, &rv[i].se);
	scanf("%d", &C);
	cv.resize(C);
	for(int i = 0; i < C; i++) scanf("%lld%lld", &cv[i].fi, &cv[i].se);

	lint sumr = 0, sumc = 0;
	for(int i = 0; i < R; i++) sumr += rv[i].fi * rv[i].se;
	for(int i = 0; i < C; i++) sumc += cv[i].fi * cv[i].se;
	if(sumr != sumc) {
		printf("0");
		return 0;
	}

	rv.push_back(make_pair(1ll << 30, 0));
	sort(rv.begin(), rv.end(), greater<pll>());
	sort(cv.begin(), cv.end(), greater<pll>());

	vector<pll> v;
	for(int i = 0; i < cv.size(); i++) {
		if(i > 0 && cv[i - 1].fi == cv[i].fi) v.back().se += cv[i].se;
		else v.push_back(cv[i]);
	}
	swap(cv, v);
	for(int i = 1; i < cv.size(); i++) cv[i].se += cv[i - 1].se;
	rv[0].fi = rv[0].fi * rv[0].se;
	for(int i = 1; i < rv.size(); i++) {
		rv[i].fi = rv[i - 1].fi + rv[i].fi * rv[i].se;
		rv[i].se += rv[i - 1].se;
	}

	/*
	for(int i = 0; i < cv.size(); i++) printf("(%lld, %lld)", cv[i].fi, cv[i].se);
	printf("\n");
	for(int i = 0; i < rv.size(); i++) printf("(%lld, %lld)", rv[i].fi, rv[i].se);
	printf("\n");
	*/

	lint A = 0ll, h = 0ll;
	int p = cv.size() - 1;
	for(int i = 1; i < rv.size(); i++) {
		//printf("h = %lld, A = %lld, p = %d\n", h, A, p);
		if(A + cv[p].se < rv[i - 1].fi + (rv[i].fi - rv[i - 1].fi) / rv[i].se) {
			printf("0");
			return 0;
		}
		while(p >= 0 && cv[p].fi <= rv[i].se) {
			A += (cv[p].fi - h) * cv[p].se;
			h = cv[p].fi;
			p--;
		}
		if(p < 0) break;
		A += (rv[i].se - h) * cv[p].se;
		h = rv[i].se;
		if(A < rv[i].fi) {
			printf("0");
			return 0;
		}
	}
	printf("1");
	return 0;
}

Compilation message

bodyguards.cpp: In function 'int main()':
bodyguards.cpp:36:29: error: 'greater' was not declared in this scope
  sort(rv.begin(), rv.end(), greater<pll>());
                             ^~~~~~~
bodyguards.cpp:36:40: error: expected primary-expression before '>' token
  sort(rv.begin(), rv.end(), greater<pll>());
                                        ^
bodyguards.cpp:36:42: error: expected primary-expression before ')' token
  sort(rv.begin(), rv.end(), greater<pll>());
                                          ^
bodyguards.cpp:37:40: error: expected primary-expression before '>' token
  sort(cv.begin(), cv.end(), greater<pll>());
                                        ^
bodyguards.cpp:37:42: error: expected primary-expression before ')' token
  sort(cv.begin(), cv.end(), greater<pll>());
                                          ^
bodyguards.cpp:40:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < cv.size(); i++) {
                 ~~^~~~~~~~~~~
bodyguards.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < cv.size(); i++) cv[i].se += cv[i - 1].se;
                 ~~^~~~~~~~~~~
bodyguards.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < rv.size(); i++) {
                 ~~^~~~~~~~~~~
bodyguards.cpp:61:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < rv.size(); i++) {
                 ~~^~~~~~~~~~~
bodyguards.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &R);
  ~~~~~^~~~~~~~~~
bodyguards.cpp:22:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < R; i++) scanf("%lld%lld", &rv[i].fi, &rv[i].se);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bodyguards.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &C);
  ~~~~~^~~~~~~~~~
bodyguards.cpp:25:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < C; i++) scanf("%lld%lld", &cv[i].fi, &cv[i].se);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~