답안 #897579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897579 2024-01-03T12:45:13 Z guechotjrhh 치료 계획 (JOI20_treatment) C++14
100 / 100
360 ms 60364 KB
#include <iostream>
#include<vector>
#include<set>
#include<map>
#include<fstream>
#include<algorithm>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
#define x first
#define y second
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define l x.x
#define r x.y
#define t y.x
#define p y.y
#define maxn (1<<17)
#define maxs (1<<18)
ll min(ll a, ll b) { return a < b ? a : b; }
ll ab(ll n) { return n > 0 ? n : -n; }

vector<int> le(maxs), ri(maxs), ind(maxs,0);
//vector<set<pi>> v(maxs);
vector<vector<pi>> v(maxs);
void bld() {
	for (int i = maxn; i < maxs; i++) {
		le[i] = ri[i] = i - maxn;
		v[i].clear();
		ind[i] = 0;
	}
	for (int i = maxn - 1; i > 0; i--) {
		le[i] = le[i << 1];
		ri[i] = ri[(i << 1) + 1];
		v[i].clear();
		ind[i] = 0;
	}
}
void insert(int i, int j, int ind) {
	i = 2 * (i + maxn);
	while (i >>= 1) v[i].push_back({j, ind});
}
/*void del(int i, int j, int ind) {
	i = 2 * (i + maxn);
	while (i >>= 1) v[i].erase(v[i].find({ j, ind }));
}*/
void que(int i, int ex, int ey,vi&res) {
	if (le[i] > ex) return;
	if (ri[i] <= ex) {
		for (; ind[i] < v[i].size() && v[i][ind[i]].x <= ey; ind[i]++) res.push_back(v[i][ind[i]].y);
		/*for (auto it : v[i]) {
			if (it.x > ey) break;
			res.push_back(it.y);
		}*/
	}
	else {
		que(i << 1, ex, ey, res);
		que((i << 1)+1, ex, ey, res);
	}
}

int s, n;
long long func(int S, int N, vector<int> T, vector<int> L, vector<int> R, vector<int> P) {
	s = S; n = N;
	bld();
	map<int, int> mp;
	for (int i = 0; i < n; i++) mp[L[i] - T[i]] = 0;
	int c = 0;
	for (auto it : mp) mp[it.x] = c++;
	ll res = 1e18;
	set<pair<ll, int>> st;
	vector < pi>vc(n);
	for (int i = 0; i < n; i++) vc[i] = {L[i]+T[i], i};
	sort(all(vc));
	for (int i = 0; i < n; i++) if (L[vc[i].y] != 1) insert(mp[L[vc[i].y]-T[vc[i].y]], vc[i].x, vc[i].y);
	vector<bool> ve(n, 0);
	for (int i = 0; i < n; i++) {
		if (L[i] == 1) {
			st.insert({ P[i],i });
			ve[i] = 1;
		}
		//else insert(mp[L[i]-T[i]],L[i]+T[i],i);
	}
	
	while (st.size()) {
		auto it = st.begin();
		int i = it->y;
		ll dst = it->x;
		st.erase(it);
		if (R[i] == s) res = min(res, dst);

		auto lt = mp.upper_bound(R[i] - T[i] + 1);
		if (lt == mp.begin()) continue;
		lt--;
		int u = lt->y;
		vector<int> vec;
		que(1, u, R[i]+T[i]+1, vec);
		for (int j : vec) {
			if (!ve[j]) {
				ve[j] = 1;
				st.insert({ dst + P[j],j });
			}
			//del(mp[L[j] - T[j]], L[j] + T[j], j);
		}
	}
	return res == 1e18 ? -1 : res;
}

void run_tests() {
	string name = "03-00.txt";
	for (int i = 1; i <= 18; i++) {
		cout << "TEST " << i << endl;
		name[3] = '0' + i / 10;
		name[4] = '0' + i % 10;
		ifstream fin("in/" + name);
		ifstream fout("out/" + name);

		int S, N;
		fin >> S >> N;

		vector<int> T(N), L(N), R(N), P(N);
		for (int i = 0; i < N; i++) fin >> T[i] >> L[i] >> R[i] >> P[i];

		ll u = func(S, N, T, L, R, P),u1;
		fout >> u1;
		if (u != u1) {
			cout << i << endl;
			cout << S << ' ' << N << endl;
			cout << u << ' ' << u1 << endl;
			//for (int i = 0; i < N; i++) cout << T[i] << ' ' << L[i] << ' ' << R[i] << ' ' << P[i] << endl;
			return;
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//run_tests();
	//return 0;

	int S, N;
	cin >> S >> N;
	
	vector<int> T(N), L(N), R(N), P(N);
	for (int i = 0; i < N; i++) cin >> T[i] >> L[i] >> R[i] >> P[i];

	cout << func(S, N, move(T), move(L), move(R), move(P)) << endl;

	return 0;
}

Compilation message

treatment.cpp: In function 'void que(int, int, int, std::vector<int>&)':
treatment.cpp:50:17: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for (; ind[i] < v[i].size() && v[i][ind[i]].x <= ey; ind[i]++) res.push_back(v[i][ind[i]].y);
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 52504 KB Output is correct
2 Correct 154 ms 52384 KB Output is correct
3 Correct 138 ms 43684 KB Output is correct
4 Correct 130 ms 42844 KB Output is correct
5 Correct 119 ms 49996 KB Output is correct
6 Correct 117 ms 48012 KB Output is correct
7 Correct 110 ms 53416 KB Output is correct
8 Correct 76 ms 44744 KB Output is correct
9 Correct 74 ms 47492 KB Output is correct
10 Correct 79 ms 52900 KB Output is correct
11 Correct 220 ms 59592 KB Output is correct
12 Correct 210 ms 58792 KB Output is correct
13 Correct 231 ms 57076 KB Output is correct
14 Correct 231 ms 56748 KB Output is correct
15 Correct 180 ms 53448 KB Output is correct
16 Correct 178 ms 53232 KB Output is correct
17 Correct 177 ms 52564 KB Output is correct
18 Correct 237 ms 58040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9560 KB Output is correct
2 Correct 3 ms 9564 KB Output is correct
3 Correct 4 ms 9716 KB Output is correct
4 Correct 3 ms 9564 KB Output is correct
5 Correct 5 ms 9564 KB Output is correct
6 Correct 3 ms 9564 KB Output is correct
7 Correct 3 ms 9632 KB Output is correct
8 Correct 4 ms 9712 KB Output is correct
9 Correct 3 ms 9560 KB Output is correct
10 Correct 3 ms 9564 KB Output is correct
11 Correct 3 ms 9720 KB Output is correct
12 Correct 3 ms 9488 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 3 ms 9716 KB Output is correct
15 Correct 3 ms 9564 KB Output is correct
16 Correct 3 ms 9564 KB Output is correct
17 Correct 3 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 3 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9560 KB Output is correct
2 Correct 3 ms 9564 KB Output is correct
3 Correct 4 ms 9716 KB Output is correct
4 Correct 3 ms 9564 KB Output is correct
5 Correct 5 ms 9564 KB Output is correct
6 Correct 3 ms 9564 KB Output is correct
7 Correct 3 ms 9632 KB Output is correct
8 Correct 4 ms 9712 KB Output is correct
9 Correct 3 ms 9560 KB Output is correct
10 Correct 3 ms 9564 KB Output is correct
11 Correct 3 ms 9720 KB Output is correct
12 Correct 3 ms 9488 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 3 ms 9716 KB Output is correct
15 Correct 3 ms 9564 KB Output is correct
16 Correct 3 ms 9564 KB Output is correct
17 Correct 3 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 3 ms 9560 KB Output is correct
20 Correct 10 ms 11356 KB Output is correct
21 Correct 11 ms 11560 KB Output is correct
22 Correct 10 ms 11960 KB Output is correct
23 Correct 10 ms 11868 KB Output is correct
24 Correct 13 ms 11868 KB Output is correct
25 Correct 12 ms 11868 KB Output is correct
26 Correct 11 ms 11868 KB Output is correct
27 Correct 9 ms 11868 KB Output is correct
28 Correct 11 ms 11868 KB Output is correct
29 Correct 10 ms 11868 KB Output is correct
30 Correct 10 ms 12044 KB Output is correct
31 Correct 9 ms 11868 KB Output is correct
32 Correct 13 ms 12120 KB Output is correct
33 Correct 11 ms 12060 KB Output is correct
34 Correct 11 ms 11868 KB Output is correct
35 Correct 12 ms 12120 KB Output is correct
36 Correct 10 ms 11996 KB Output is correct
37 Correct 10 ms 11868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 52504 KB Output is correct
2 Correct 154 ms 52384 KB Output is correct
3 Correct 138 ms 43684 KB Output is correct
4 Correct 130 ms 42844 KB Output is correct
5 Correct 119 ms 49996 KB Output is correct
6 Correct 117 ms 48012 KB Output is correct
7 Correct 110 ms 53416 KB Output is correct
8 Correct 76 ms 44744 KB Output is correct
9 Correct 74 ms 47492 KB Output is correct
10 Correct 79 ms 52900 KB Output is correct
11 Correct 220 ms 59592 KB Output is correct
12 Correct 210 ms 58792 KB Output is correct
13 Correct 231 ms 57076 KB Output is correct
14 Correct 231 ms 56748 KB Output is correct
15 Correct 180 ms 53448 KB Output is correct
16 Correct 178 ms 53232 KB Output is correct
17 Correct 177 ms 52564 KB Output is correct
18 Correct 237 ms 58040 KB Output is correct
19 Correct 3 ms 9560 KB Output is correct
20 Correct 3 ms 9564 KB Output is correct
21 Correct 4 ms 9716 KB Output is correct
22 Correct 3 ms 9564 KB Output is correct
23 Correct 5 ms 9564 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
25 Correct 3 ms 9632 KB Output is correct
26 Correct 4 ms 9712 KB Output is correct
27 Correct 3 ms 9560 KB Output is correct
28 Correct 3 ms 9564 KB Output is correct
29 Correct 3 ms 9720 KB Output is correct
30 Correct 3 ms 9488 KB Output is correct
31 Correct 3 ms 9564 KB Output is correct
32 Correct 3 ms 9716 KB Output is correct
33 Correct 3 ms 9564 KB Output is correct
34 Correct 3 ms 9564 KB Output is correct
35 Correct 3 ms 9564 KB Output is correct
36 Correct 3 ms 9564 KB Output is correct
37 Correct 3 ms 9560 KB Output is correct
38 Correct 10 ms 11356 KB Output is correct
39 Correct 11 ms 11560 KB Output is correct
40 Correct 10 ms 11960 KB Output is correct
41 Correct 10 ms 11868 KB Output is correct
42 Correct 13 ms 11868 KB Output is correct
43 Correct 12 ms 11868 KB Output is correct
44 Correct 11 ms 11868 KB Output is correct
45 Correct 9 ms 11868 KB Output is correct
46 Correct 11 ms 11868 KB Output is correct
47 Correct 10 ms 11868 KB Output is correct
48 Correct 10 ms 12044 KB Output is correct
49 Correct 9 ms 11868 KB Output is correct
50 Correct 13 ms 12120 KB Output is correct
51 Correct 11 ms 12060 KB Output is correct
52 Correct 11 ms 11868 KB Output is correct
53 Correct 12 ms 12120 KB Output is correct
54 Correct 10 ms 11996 KB Output is correct
55 Correct 10 ms 11868 KB Output is correct
56 Correct 171 ms 45016 KB Output is correct
57 Correct 173 ms 46908 KB Output is correct
58 Correct 185 ms 55072 KB Output is correct
59 Correct 178 ms 55212 KB Output is correct
60 Correct 204 ms 53080 KB Output is correct
61 Correct 171 ms 55076 KB Output is correct
62 Correct 165 ms 45304 KB Output is correct
63 Correct 158 ms 52868 KB Output is correct
64 Correct 163 ms 52776 KB Output is correct
65 Correct 172 ms 52720 KB Output is correct
66 Correct 192 ms 52224 KB Output is correct
67 Correct 266 ms 53532 KB Output is correct
68 Correct 246 ms 53168 KB Output is correct
69 Correct 200 ms 54692 KB Output is correct
70 Correct 344 ms 53420 KB Output is correct
71 Correct 313 ms 54092 KB Output is correct
72 Correct 196 ms 54136 KB Output is correct
73 Correct 306 ms 52876 KB Output is correct
74 Correct 201 ms 53200 KB Output is correct
75 Correct 138 ms 53900 KB Output is correct
76 Correct 236 ms 59232 KB Output is correct
77 Correct 311 ms 58972 KB Output is correct
78 Correct 256 ms 57392 KB Output is correct
79 Correct 329 ms 53680 KB Output is correct
80 Correct 204 ms 53848 KB Output is correct
81 Correct 204 ms 52588 KB Output is correct
82 Correct 199 ms 53580 KB Output is correct
83 Correct 248 ms 53188 KB Output is correct
84 Correct 313 ms 52060 KB Output is correct
85 Correct 281 ms 55620 KB Output is correct
86 Correct 221 ms 53336 KB Output is correct
87 Correct 268 ms 54188 KB Output is correct
88 Correct 178 ms 58144 KB Output is correct
89 Correct 206 ms 55728 KB Output is correct
90 Correct 298 ms 59104 KB Output is correct
91 Correct 332 ms 56672 KB Output is correct
92 Correct 258 ms 53680 KB Output is correct
93 Correct 300 ms 54700 KB Output is correct
94 Correct 175 ms 54112 KB Output is correct
95 Correct 273 ms 55192 KB Output is correct
96 Correct 337 ms 59012 KB Output is correct
97 Correct 306 ms 59380 KB Output is correct
98 Correct 360 ms 60328 KB Output is correct
99 Correct 309 ms 59608 KB Output is correct
100 Correct 197 ms 54808 KB Output is correct
101 Correct 314 ms 59136 KB Output is correct
102 Correct 273 ms 60364 KB Output is correct
103 Correct 247 ms 54268 KB Output is correct