Submission #130905

# Submission time Handle Problem Language Result Execution time Memory
130905 2019-07-16T08:26:52 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;
	
	if(l == 0) for(; ; );
	
	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:48:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = s + e >> 1;
         ~~^~~
bodyguards.cpp: In function 'int main()':
bodyguards.cpp:75:8: warning: unused variable 'j' [-Wunused-variable]
  ll i, j, x, y;
        ^
bodyguards.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
bodyguards.cpp:80: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:96:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &m);
  ~~~~~^~~~~~~~~~~~
bodyguards.cpp:99: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 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 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 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 256 KB Output is correct
5 Runtime error 664 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 717 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 685 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 1080 ms 236560 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 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 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 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 632 KB Output is correct
2 Correct 7 ms 504 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 632 KB Output is correct
6 Correct 18 ms 632 KB Output is correct
7 Correct 14 ms 632 KB Output is correct
8 Correct 16 ms 760 KB Output is correct
9 Correct 20 ms 752 KB Output is correct
10 Correct 20 ms 760 KB Output is correct
11 Correct 19 ms 632 KB Output is correct
12 Correct 18 ms 632 KB Output is correct
13 Correct 15 ms 632 KB Output is correct
14 Correct 14 ms 712 KB Output is correct
15 Correct 14 ms 760 KB Output is correct
16 Correct 13 ms 632 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 1084 ms 165732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 326 ms 6424 KB Output is correct
2 Correct 179 ms 5368 KB Output is correct
3 Correct 414 ms 7364 KB Output is correct
4 Correct 45 ms 1400 KB Output is correct
5 Correct 431 ms 8272 KB Output is correct
6 Correct 328 ms 6528 KB Output is correct
7 Correct 395 ms 7780 KB Output is correct
8 Correct 46 ms 1272 KB Output is correct
9 Correct 463 ms 8284 KB Output is correct
10 Correct 374 ms 6776 KB Output is correct
11 Correct 224 ms 6776 KB Output is correct
12 Correct 222 ms 6776 KB Output is correct
13 Correct 466 ms 8316 KB Output is correct
14 Execution timed out 1072 ms 163468 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 124704 KB Time limit exceeded
2 Halted 0 ms 0 KB -