답안 #219359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219359 2020-04-05T07:36:51 Z maruii 치료 계획 (JOI20_treatment) C++14
4 / 100
157 ms 14064 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
#define ff first
#define ss second
#define eack emplace_back
#define all(x) (x).begin(), (x).end()

const ll INF = 1e18;
int N, M;
ll ans = INF;
map<int, vector<pair<pii, int>>> MP;


struct X {
	set<pil> S;
	void add(pil v) {
		auto it = S.lower_bound(pil(v.ff, 0));
		if (it != S.end() && it->ss <= v.ss) return;
		if (it == S.begin()) {
			if (it->ff == v.ff) S.erase(it);
			S.insert(v);
			return;
		}
		if (it->ff == v.ff) S.erase(it--);
		else --it;
		while (1) {
			if (it->ss >= v.ss) {
				if (it == S.begin()) {
					S.erase(it);
					break;
				}
				S.erase(it--);
			}
			else break;
		}
		S.insert(v);
	}

	void update(int s, int e, int v) {
		auto it = S.lower_bound(pil(s - 1, 0));
		if (it == S.end()) return;
		add(pil(e, it->ss + v));
	}
} a, b;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= M; ++i) {
		int t, l, r, c; cin >> t >> l >> r >> c;
		MP[t].eack(pii(l, r), c);
	}
	for (auto &i : MP) {
		int t = i.ff;
		sort(all(i.ss));
		for (auto it = a.S.begin(); it != a.S.end();) {
			if (it->ff > t) break;
			a.S.erase(it++);
		}
		for (auto it = b.S.begin(); it != b.S.end();) {
			if (it->ff > t) break;
			b.S.erase(it++);
		}
		a.S.insert(pil(t, 0));
		for (auto &j : i.ss) {
			a.update(t + j.ff.ff, t + j.ff.ss, j.ss);
			j.ff.ff = N + 1 - j.ff.ff;
			j.ff.ss = N + 1 - j.ff.ss;
			swap(j.ff.ff, j.ff.ss);
		}
		sort(all(i.ss));
		b.S.insert(pil(t, 0));
		for (auto &j : i.ss) b.update(t + j.ff.ff, t + j.ff.ss, j.ss);
		if (a.S.rbegin()->ff - t >= N - (b.S.rbegin()->ff - t)) {
			auto it = a.S.lower_bound(pil(N - (b.S.rbegin()->ff - t) + t, 0));
			ans = min(b.S.rbegin()->ss + it->ss, ans);
		}
	}
	if (ans == INF) ans = -1;
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 14064 KB Output is correct
2 Correct 121 ms 7784 KB Output is correct
3 Correct 113 ms 7956 KB Output is correct
4 Correct 117 ms 7784 KB Output is correct
5 Correct 72 ms 2032 KB Output is correct
6 Correct 73 ms 2032 KB Output is correct
7 Correct 90 ms 3048 KB Output is correct
8 Correct 72 ms 2028 KB Output is correct
9 Correct 64 ms 2032 KB Output is correct
10 Correct 63 ms 2032 KB Output is correct
11 Correct 79 ms 2032 KB Output is correct
12 Correct 78 ms 2032 KB Output is correct
13 Correct 79 ms 2032 KB Output is correct
14 Correct 80 ms 2028 KB Output is correct
15 Correct 83 ms 2032 KB Output is correct
16 Correct 92 ms 2048 KB Output is correct
17 Correct 79 ms 2028 KB Output is correct
18 Correct 75 ms 2056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 4 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 4 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 14064 KB Output is correct
2 Correct 121 ms 7784 KB Output is correct
3 Correct 113 ms 7956 KB Output is correct
4 Correct 117 ms 7784 KB Output is correct
5 Correct 72 ms 2032 KB Output is correct
6 Correct 73 ms 2032 KB Output is correct
7 Correct 90 ms 3048 KB Output is correct
8 Correct 72 ms 2028 KB Output is correct
9 Correct 64 ms 2032 KB Output is correct
10 Correct 63 ms 2032 KB Output is correct
11 Correct 79 ms 2032 KB Output is correct
12 Correct 78 ms 2032 KB Output is correct
13 Correct 79 ms 2032 KB Output is correct
14 Correct 80 ms 2028 KB Output is correct
15 Correct 83 ms 2032 KB Output is correct
16 Correct 92 ms 2048 KB Output is correct
17 Correct 79 ms 2028 KB Output is correct
18 Correct 75 ms 2056 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Incorrect 4 ms 384 KB Output isn't correct
25 Halted 0 ms 0 KB -