Submission #95031

# Submission time Handle Problem Language Result Execution time Memory
95031 2019-01-27T05:25:09 Z Retro3014 Pyramid Base (IOI08_pyramid_base) C++17
70 / 100
5000 ms 138964 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>

using namespace std;
typedef long long ll;

int N, M, P;
struct SEG{
	SEG (int l, int r, ll lazy, ll mn) : l(l), r(r), lazy(lazy), mn(mn)	{}
	int l, r;
	ll lazy, mn;
};
vector<SEG> seg;
SEG ss(-1, -1, 0, 0);
struct SQ{
	SQ (int x1, int x2, int y1, int y2, ll c) : x1(x1), x2(x2), y1(y1), y2(y2), c(c) {}
	int x1, x2, y1, y2;
	ll c;
};
vector<SQ> sc;
ll B;
struct LINE{
	LINE (int x, int y1, int y2, ll c) : x(x), y1(y1), y2(y2), c(c) {}
	int x, y1, y2;
	ll c;
	bool operator <(const LINE &a)const{
		return x<a.x;
	}
};
vector<LINE> line;

void lazy(int idx, int s, int e, int l, int r, ll cost){
	if(seg[idx].lazy!=0){
		if(seg[idx].l==-1)	{seg[idx].l = seg.size(); seg.push_back(ss);}
		if(seg[idx].r==-1)	{seg[idx].r = seg.size(); seg.push_back(ss);}
		seg[seg[idx].l].lazy+=seg[idx].lazy; seg[seg[idx].l].mn += seg[idx].lazy;
		seg[seg[idx].r].lazy+=seg[idx].lazy; seg[seg[idx].r].mn += seg[idx].lazy;
		seg[idx].lazy = 0;
	}
	if(l<=s && e<=r){
		seg[idx].lazy+=cost;	seg[idx].mn+=cost;	return;
	}
	if(e<l || s>r)	return;
	if(seg[idx].l==-1)	{seg[idx].l = seg.size(); seg.push_back(ss);}
	if(seg[idx].r==-1)	{seg[idx].r = seg.size(); seg.push_back(ss);}
	lazy(seg[idx].l, s, (s+e)/2, l, r, cost);
	lazy(seg[idx].r, (s+e)/2+1, e, l, r, cost);
	seg[idx].mn = min(seg[seg[idx].l].mn, seg[seg[idx].r].mn);
}

int main(){
	scanf("%d%d", &N, &M);
	N*=2; M*=2;
	scanf("%lld", &B);
	scanf("%d", &P);	
	for(int i=0; i<P; i++){
		int a, b, c, d, e;
		scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
		a--; b--;
		sc.push_back({a*2, c*2, b*2, d*2, (ll)e});
	}
	int s = 0, e = (min(N, M))/2, m;
	while(s<e){
		m = (s+e)/2+1;
		seg.clear();
		seg.push_back({-1, -1, 0, 0});
		line.clear();
		for(int i=0; i<sc.size(); i++){
			SQ now = sc[i];
			now.x1-=(m-1);	now.y1-=(m-1); now.x2+=(m-1); now.y2+=(m-1);
			line.push_back({max(m, now.x1), max(m, now.y1), min(M-m, now.y2), now.c});
			line.push_back({max(m, now.x2), max(m, now.y1), min(M-m, now.y2), -now.c});
		}
		line.push_back({m, m, m, 0});
		sort(line.begin(), line.end());
		//printf("%d\n", m);
		for(int i=0; i<line.size(); i++){
			//printf("%d %d %d %lld\n", line[i].x, line[i].y1, line[i].y2, line[i].c);
			if(line[i].x>N-m)	break;
			if(i!=0 && line[i].x!=line[i-1].x){
				if(seg[0].mn<=B){
					s = m;	break;
				}
			}
			lazy(0, m, M-m, line[i].y1, line[i].y2, line[i].c);
		}
		if(seg[0].mn<=B){
			s = m;
		}
		if(s==m)	continue;
		else	e = m-1;
	}
	printf("%d", s);
	return 0;
}

Compilation message

pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:70:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<sc.size(); i++){
                ~^~~~~~~~~~
pyramid_base.cpp:79:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<line.size(); i++){
                ~^~~~~~~~~~~~
pyramid_base.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
pyramid_base.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &B);
  ~~~~~^~~~~~~~~~~~
pyramid_base.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &P); 
  ~~~~~^~~~~~~~~~
pyramid_base.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1292 KB Output is correct
2 Correct 32 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3724 KB Output is correct
2 Correct 12 ms 1420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1720 KB Output is correct
2 Correct 75 ms 2480 KB Output is correct
3 Correct 71 ms 2480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 8040 KB Output is correct
2 Correct 607 ms 14272 KB Output is correct
3 Correct 439 ms 8156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 315 ms 14812 KB Output is correct
2 Correct 32 ms 2928 KB Output is correct
3 Correct 270 ms 27128 KB Output is correct
4 Correct 643 ms 27208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 645 ms 15364 KB Output is correct
2 Correct 1424 ms 27592 KB Output is correct
3 Correct 143 ms 9188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 408 ms 15812 KB Output is correct
2 Correct 1977 ms 28108 KB Output is correct
3 Correct 1801 ms 28104 KB Output is correct
4 Correct 2015 ms 28112 KB Output is correct
5 Correct 1996 ms 28012 KB Output is correct
6 Correct 119 ms 9704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5097 ms 118856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5084 ms 128824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5093 ms 138964 KB Time limit exceeded
2 Halted 0 ms 0 KB -