Submission #130899

# Submission time Handle Problem Language Result Execution time Memory
130899 2019-07-16T08:22:47 Z 김세빈(#3168) Bodyguards (CEOI10_bodyguards) C++14
0 / 100
1000 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

set <pll> S;
pll D[202020];
ll n, m;

void die() { printf("0\n"); exit(0); }

void print(set <pll> &S) { for(pll p: S) printf("(%lld %lld) ", p.first, p.second); printf("\n"); }

void query(ll x, ll y1, ll v)
{
	if(y1 == 0 && v == 0) return;
	
	pll p1, p2;
	ll k, l, s, e, mid;
	ll y, y2, y3;
	
	auto it = S.lower_bound(pll(x, -1));
	if(it == S.end()) die();
	
	if(y1 == 0){
		p1 = p2 = *it;
		p1.first -= v; p1.second = 1;
		p2.second --;
		
		S.erase(it);
		S.insert(p1); S.insert(p2);
		
		return;
	}
	
	k = x - prev(it) -> first;
	l = it -> first - prev(it) -> first;
	
	for(s=0, e=y1+y1; s<=e; ){
		mid = s + e >> 1;
		if(mid <= prev(it) -> second + (v + mid * k) / l) s = mid + 1;
		else e = mid - 1;
	}
	
	y2 = s - 1;
	y3 = (l * it -> second - v - 1) / k + 1;
	
	y = min(y1, min(y2, y3));
	
	p1 = *it; p2 = *prev(it);
	p1.second -= (v + y * k) / l;
	p2.second += (v + y * k) / l - y;
	v = (v + y * k) % l;
	
	S.erase(prev(it));
	it = S.lower_bound(pll(x, -1));
	S.erase(it);
	
	if(p1.second) S.insert(p1);
	if(p2.second) S.insert(p2);
	
//	print(S);
	if(y == 0 && p1.second && p2.second) 1 / 0;
	
	query(x, y1 - y, v);
}

int main()
{
	ll i, j, x, y;
	
	scanf("%lld", &n);
	
	for(i=1; i<=n; i++){
		scanf("%lld%lld", &D[i].first, &D[i].second);
	}
	
	sort(D + 1, D + n + 1);
	reverse(D + 1, D + n + 1);
	
	S.insert(pll(0, 1e18));
	
	for(i=1; i<=n; i++){
		D[i].first -= D[i + 1].first;
		D[i].second += D[i - 1].second;
		S.insert(pll(D[i].second, D[i].first));
	}
	
//	print(S);
	
	scanf("%lld", &m);
	
	for(i=0; i<m; i++){
		scanf("%lld%lld", &x, &y);
		if(x) query(x, y, 0);
//		print(S);
	}
	
	printf("1\n");
	
	return 0;
}

Compilation message

bodyguards.cpp: In function 'void query(ll, ll, ll)':
bodyguards.cpp:42:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = s + e >> 1;
         ~~^~~
bodyguards.cpp:65:41: warning: division by zero [-Wdiv-by-zero]
  if(y == 0 && p1.second && p2.second) 1 / 0;
                                       ~~^~~
bodyguards.cpp:65:41: warning: statement has no effect [-Wunused-value]
bodyguards.cpp: In function 'int main()':
bodyguards.cpp:72:8: warning: unused variable 'j' [-Wunused-variable]
  ll i, j, x, y;
        ^
bodyguards.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
bodyguards.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &D[i].first, &D[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bodyguards.cpp:93:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &m);
  ~~~~~^~~~~~~~~~~~
bodyguards.cpp:96:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Runtime error 651 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 686 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 714 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 674 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1103 ms 244088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Execution timed out 1095 ms 228888 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 789 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 166856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 162156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 126328 KB Time limit exceeded
2 Halted 0 ms 0 KB -