Submission #130901

# Submission time Handle Problem Language Result Execution time Memory
130901 2019-07-16T08:25:02 Z 김세빈(#3168) Bodyguards (CEOI10_bodyguards) C++14
20 / 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 --;
		
		if(p1.first == prev(it) -> first) p1.second = 0;
		
		S.erase(it);
		
		if(p1.second) S.insert(p1);
		if(p2.second) 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);
	
	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:46:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = s + e >> 1;
         ~~^~~
bodyguards.cpp: In function 'int main()':
bodyguards.cpp:73:8: warning: unused variable 'j' [-Wunused-variable]
  ll i, j, x, y;
        ^
bodyguards.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
bodyguards.cpp:78: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:94:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &m);
  ~~~~~^~~~~~~~~~~~
bodyguards.cpp:97: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 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 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 252 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Runtime error 641 ms 262148 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 Correct 2 ms 256 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 Runtime error 656 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 711 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 684 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 1099 ms 241364 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 632 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 9 ms 504 KB Output is correct
4 Correct 9 ms 888 KB Output is correct
5 Correct 12 ms 504 KB Output is correct
6 Correct 17 ms 632 KB Output is correct
7 Correct 15 ms 632 KB Output is correct
8 Correct 15 ms 632 KB Output is correct
9 Correct 20 ms 632 KB Output is correct
10 Correct 20 ms 632 KB Output is correct
11 Correct 18 ms 632 KB Output is correct
12 Correct 18 ms 760 KB Output is correct
13 Correct 15 ms 632 KB Output is correct
14 Correct 14 ms 760 KB Output is correct
15 Correct 14 ms 632 KB Output is correct
16 Correct 13 ms 760 KB Output is correct
17 Correct 14 ms 760 KB Output is correct
18 Correct 18 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1042 ms 158756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 323 ms 6392 KB Output is correct
2 Correct 175 ms 5496 KB Output is correct
3 Correct 409 ms 7392 KB Output is correct
4 Correct 47 ms 1400 KB Output is correct
5 Correct 430 ms 8308 KB Output is correct
6 Correct 295 ms 6652 KB Output is correct
7 Correct 392 ms 7672 KB Output is correct
8 Correct 45 ms 1272 KB Output is correct
9 Correct 459 ms 8404 KB Output is correct
10 Correct 377 ms 6932 KB Output is correct
11 Correct 239 ms 6904 KB Output is correct
12 Correct 221 ms 6904 KB Output is correct
13 Correct 464 ms 8416 KB Output is correct
14 Execution timed out 1083 ms 165264 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 124620 KB Time limit exceeded
2 Halted 0 ms 0 KB -