Submission #54004

# Submission time Handle Problem Language Result Execution time Memory
54004 2018-07-02T08:06:02 Z 윤교준(#1456) Pyramid Base (IOI08_pyramid_base) C++11
0 / 100
1173 ms 55356 KB
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <queue>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXN = 1000005;
const int MAXM = 1000005;
const int MAXK = 400005;
const int MX = 524288;

struct TC1SEG {
	TC1SEG() { init(); }
	ll d[MAXM*3], e[MAXM*3];
	int M;
	void init() {
		fill(d, d + MAXM * 3, 0);
		fill(e, e + MAXM * 3, 0);
	}
	void upd(int i, int s, int e, int p, int q, int r) {
		if (q < p || e < p || q < s) return;
		if (p <= s && e <= q) {
			TC1SEG::e[i] += r;
			if (s == e) {
				d[i] = TC1SEG::e[i];
			}
			else {
				d[i] = min(d[i * 2], d[i * 2 + 1]) + TC1SEG::e[i];
			}
			return;
		}
		int m = (s + e) / 2;
		upd(i * 2, s, m, p, q, r);
		upd(i * 2 + 1, m + 1, e, p, q, r);
		d[i] = min(d[i * 2], d[i * 2 + 1]) + TC1SEG::e[i];
	}
	void upd(int p, int q, int r) {
		upd(1, 1, M, p, q, r);
	}
	ll get(int i, int s, int e, int p, int q) {
		if (q < p || e < p || q < s) return INFLL;
		if (p <= s && e <= q) return d[i];
		int m = (s + e) / 2;
		return min(get(i * 2, s, m, p, q), get(i * 2 + 1, m + 1, e, p, q));
	}
	ll get(int s, int e) {
		return get(1, 1, M, s, e);
	}
} tc1seg;

struct EVTTC1 {
	EVTTC1(int type, int x, int a, int b, int c)
		: type(type), x(x), a(a), b(b), c(c) {}
	int type, x, a, b, c;

	bool operator < (const EVTTC1 &t) const {
		if (x != t.x) return x < t.x;
		return type < t.type;
	}
};

int SX[MAXK], EX[MAXK], SY[MAXK], EY[MAXK], A[MAXK];

int N, M, K, B;

bool isPossibleTC1(int L) {
	tc1seg.init();
	tc1seg.M = ::N;
	vector<EVTTC1> EV;
	EV.emplace_back(3, 1, 0, 0, 0);
	for (int i = 1, t; i <= K; i++) {
		t = EX[i] + 1;
		if (M < t + L - 1) continue;
		EV.emplace_back(3, t, 0, 0, 0);
	}
	for (int i = 1; i <= K; i++) {
		EV.emplace_back(1, max(1, SX[i] - L + 1), max(1, SY[i] - L + 1), EY[i], A[i]);
		EV.emplace_back(2, EX[i] + 1, max(1, SY[i] - L + 1), EY[i], -A[i]);
	}
	sorv(EV);

	ll ret = INFLL;

	for (auto &e : EV) {
		if (e.type < 3) {
			//printf("UPD %d : %d %d %d\n", e.x, e.a, e.b, e.c);
			tc1seg.upd(e.a, e.b, e.c);
		}
		else {
			//printf("QUR %d : %d %d :: %lld\n", e.x, 1, N - L + 1, tc1seg.get(1, N-L+1));
			upmin(ret, tc1seg.get(1, N-L+1));
		}
	}

	//printf("L=%d, ret=%lld\n", L, ret);

	return ret <= B;
}
int doTC1() {
	int s = 0, e = min(N, M); for (int m, t; s < e;) {
		m = (s + e + 1) / 2;
		t = isPossibleTC1(m);
		//printf("%d %d %d : %d\n", s, e, m, t);
		if(t) s = m;
		else e = m - 1;
	}
	return s;
}

int doTC2() {
	return 0;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);

	cin >> M >> N >> B >> K;
	for (int i = 1; i <= K; i++) {
		cin >> SX[i] >> SY[i] >> EX[i] >> EY[i] >> A[i];
		//printf("%d : %d %d %d %d\n", i, SX[i], EX[i], SY[i], EY[i]);
	}

	if (B) {
		cout << doTC1() << endl;
	}
	else {
		cout << doTC2() << endl;
	}

	//while (getchar());

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 47352 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 47352 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 47408 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 47444 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 47444 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 47444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 47564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 48280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 423 ms 49784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 983 ms 50316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 974 ms 50476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1173 ms 52036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 52036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 291 ms 53424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 242 ms 55356 KB Output isn't correct
2 Halted 0 ms 0 KB -