답안 #68062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68062 2018-08-15T20:48:26 Z spencercompton Pyramid Base (IOI08_pyramid_base) C++14
70 / 100
5000 ms 139644 KB
#include <bits/stdc++.h>
using namespace std;
int inf = 2000000069;
class Node{
public:
	Node *l, *r;
	int mini, lazy, s, e;
	bool res;
	Node (int a, int b){
		s = a;
		e = b;
		lazy = 0;
		mini = 0;
		res = false;
		if(s==e){
			l = NULL;
			r = NULL;
		}
		else{
			l = new Node(s,(s+e)/2);
			r = new Node((s+e)/2+1,e);
		}
	}
	void push(){
		if(s!=e && res){
			res = false;
			l->mini = 0;
			l->lazy = 0;
			l->res = true;
			r->mini = 0;
			r->lazy = 0;
			r->res = true;
			res = false;
		}
	    if(s!=e && lazy!=0){
	        l->mini += lazy;
	        l->lazy += lazy;
	        r->mini += lazy;
	        r->lazy += lazy;
	        lazy = 0;
	    }
	}
	void pull(){
	    if(s!=e){
	        mini = min(l->mini,r->mini);
	    }
	}
	void add(int st, int en, int val){
		if(st<=s && e <= en){
			lazy += val;
			mini += val;
			return;
		}
		push();
		if(st<=(s+e)/2){
			l->add(st,en,val);
		}
		if(en>(s+e)/2){
			r->add(st,en,val);
		}
		pull();
	}
	// int gmin(int st, int en){
	// 	if(st<=s && e <= en){
	// 		return mini;
	// 	}
	// 	push();
	// 	int ret = inf;
	// 	if(st<=(s+e)/2){
	// 		ret = min(ret,l->gmin(st,en));
	// 	}
	// 	if(en>(s+e)/2){
	// 		ret = min(ret,r->gmin(st,en));
	// 	}
	// 	return ret;
	// }
};

class Obj{
public:
	int x, y1, y2, c;
	bool add;
	Obj(int a , int b, int d, int e, bool f){
		x = a;
		y1 = b;
		y2 = d;
		c = e;
		add = f;
	}
	bool operator<(const Obj &o) const{
		if(x!=o.x){
			return x<o.x;
		}
		if(add && !o.add){
			return true;
		}
		return false;
	}
};

class Rect{
public:
	//get Rekt
	int x1, y1, x2, y2, c;
	Rect(int a, int b, int d, int e, int f){
		x1 = a;
		y1 = b;
		x2 = d;
		y2 = e;
		c = f;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int col, row, bud, p;
	cin >> col >> row >> bud >> p;
	vector<Rect> li;
	for(int i = 0; i<p; i++){
		int a, b,c,d,e;
		cin >> a >> b >> c >> d >> e;
		a--;
		b--;
		c--;
		d--;
		if(bud==0){
			e = 1;
		}
		li.push_back(Rect(a,b,c,d,e));
	}
	Node *t = new Node(0,row-1);
	int lo = 0;
	int hi = min(col,row);
	while(lo<hi){
		int mid = (lo+hi+1)/2;
		bool ok = false;
		vector<Obj> li2;
		int f = 0;
		int s = row-mid;
		int last = col-mid;
		for(int i = 0; i<p; i++){
			li2.push_back(Obj(max(0,li[i].x1-mid+1),max(0,li[i].y1-mid+1),li[i].y2,li[i].c,true));
			if(li2.back().x>last){
				li2.pop_back();
			}
			li2.push_back(Obj(li[i].x2+1,max(0,li[i].y1-mid+1),li[i].y2,li[i].c,false));
			if(li2.back().x>last){
				li2.pop_back();
			}
		}
		sort(li2.begin(),li2.end());
		if(s<row-1){
			t->add(s+1,row-1,bud+1);
		}
		bool zero = true;
		for(int i =0; i<li2.size() && !ok; i++){
			if(zero && li2[i].x>0){
				zero = false;
				ok |= t->mini<=bud;
				if(ok){
					break;
				}
			}
			if(li2[i].x>last){
				break;
			}
			if(li2[i].add){
				t->add(li2[i].y1,li2[i].y2,li2[i].c);
			}
			else{
				t->add(li2[i].y1,li2[i].y2,-li2[i].c);
				ok |= t->mini<=bud;
			}
		}
		if(!ok){
			ok |= t->mini<=bud;
		}
		if(ok){
			lo = mid;
		}
		else{
			hi = mid-1;
		}
		t->res = true;
		t->mini = 0;
		t->lazy = 0;
	}
	cout << lo << endl;
}

Compilation message

pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:157:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i =0; i<li2.size() && !ok; i++){
                 ~^~~~~~~~~~~
pyramid_base.cpp:139:7: warning: unused variable 'f' [-Wunused-variable]
   int f = 0;
       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 94660 KB Output is correct
2 Correct 169 ms 94660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 94812 KB Output is correct
2 Correct 151 ms 94916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 94916 KB Output is correct
2 Correct 76 ms 94916 KB Output is correct
3 Correct 66 ms 94916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 94916 KB Output is correct
2 Correct 585 ms 94916 KB Output is correct
3 Correct 462 ms 94916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 804 ms 97872 KB Output is correct
2 Correct 57 ms 97872 KB Output is correct
3 Correct 445 ms 97872 KB Output is correct
4 Correct 969 ms 98772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1268 ms 98884 KB Output is correct
2 Correct 1637 ms 99040 KB Output is correct
3 Correct 778 ms 99040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1234 ms 99040 KB Output is correct
2 Correct 2208 ms 99420 KB Output is correct
3 Correct 2222 ms 99420 KB Output is correct
4 Correct 2385 ms 99460 KB Output is correct
5 Correct 2481 ms 99460 KB Output is correct
6 Correct 795 ms 99460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5020 ms 118276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5040 ms 134204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5084 ms 139644 KB Time limit exceeded
2 Halted 0 ms 0 KB -