Submission #261296

# Submission time Handle Problem Language Result Execution time Memory
261296 2020-08-11T15:56:56 Z Saboon Treatment Project (JOI20_treatment) C++14
39 / 100
1713 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 10;

ll T[maxn], L[maxn], R[maxn], C[maxn], p[maxn], dp[maxn];
vector<pair<int,ll>> g[maxn];

void dijkstra(int v){
	memset(dp, -1, sizeof dp);
	set<pair<ll,int>> s;
	dp[v] = 0;
	s.insert({dp[v], v});
	while (!s.empty()){
		v = (*s.begin()).second;
		s.erase(s.begin());
		for (auto [u, w] : g[v]){
			if (dp[u] == -1 or dp[u] > dp[v] + w){
				s.erase({dp[u],u});
				dp[u] = dp[v] + w;
				s.insert({dp[u],u});
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	for (ll i = 1; i <= m; i++)
		cin >> T[i] >> L[i] >> R[i] >> C[i];
	if (*max_element(T+1, T+m+1) == 1){
		for (ll i = 1; i <= m; i++)
			p[i] = i;
		sort(p+1, p+m+1, [](ll a, ll b){ return R[a] < R[b]; });
		vector<ll> S;
		for (ll iit = 1; iit <= m; iit++){
			ll i = p[iit];
			if (L[i] == 1)
				dp[i] = C[i];
			else
				dp[i] = -1;
			if (S.empty()){
				if (dp[i] != -1)
					S.push_back(i);
				continue;
			}
			ll lo = -1, hi = S.size();
			while (hi - lo > 1){
				ll mid = (lo + hi) >> 1;
				if (R[S[mid]]+1 < L[i])
					lo = mid;
				else
					hi = mid;
			}
			if (hi == S.size())
				continue;
			if (dp[i] == -1 or dp[i] > dp[S[hi]] + C[i])
				dp[i] = dp[S[hi]] + C[i];
			while (!S.empty() and dp[S.back()] >= dp[i])
				S.pop_back();
			S.push_back(i);
		}
		ll answer = -1;
		for (ll i = 1; i <= m; i++)
			if (R[i] == n and dp[i] != -1 and (answer == -1 or answer > dp[i]))
				answer = dp[i];
		cout << answer << endl;
		return 0;
	}
	for (ll i = 1; i <= m; i++)
		p[i] = i;
	for (int i = 1; i <= m; i++){
		if (L[i] == 1)
			g[0].push_back({i,C[i]});
		if (R[i] == n)
			g[i].push_back({m+1, 0});
		for (int j = 1; j <= m; j++){
			if (abs(T[i]-T[j]) <= R[j] - L[i] + 1){
				g[j].push_back({i, C[i]});
			}
		}
		
	}
	dijkstra(0);
	cout << dp[m+1] << endl;
}

Compilation message

treatment.cpp: In function 'void dijkstra(int)':
treatment.cpp:17:13: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
   for (auto [u, w] : g[v]){
             ^
treatment.cpp: In function 'int main()':
treatment.cpp:57:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (hi == S.size())
        ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 101 ms 12532 KB Output is correct
2 Correct 96 ms 12024 KB Output is correct
3 Correct 83 ms 12024 KB Output is correct
4 Correct 82 ms 12024 KB Output is correct
5 Correct 73 ms 11384 KB Output is correct
6 Correct 81 ms 11512 KB Output is correct
7 Correct 81 ms 11640 KB Output is correct
8 Correct 70 ms 11384 KB Output is correct
9 Correct 73 ms 11388 KB Output is correct
10 Correct 68 ms 11384 KB Output is correct
11 Correct 74 ms 11384 KB Output is correct
12 Correct 78 ms 11384 KB Output is correct
13 Correct 82 ms 11384 KB Output is correct
14 Correct 86 ms 11384 KB Output is correct
15 Correct 84 ms 11380 KB Output is correct
16 Correct 85 ms 11384 KB Output is correct
17 Correct 76 ms 11512 KB Output is correct
18 Correct 67 ms 11384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6656 KB Output is correct
2 Correct 5 ms 6656 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 6 ms 6656 KB Output is correct
5 Correct 7 ms 6656 KB Output is correct
6 Correct 5 ms 6656 KB Output is correct
7 Correct 5 ms 6656 KB Output is correct
8 Correct 5 ms 6656 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 5 ms 6656 KB Output is correct
11 Correct 5 ms 6656 KB Output is correct
12 Correct 5 ms 6656 KB Output is correct
13 Correct 5 ms 6656 KB Output is correct
14 Correct 6 ms 6784 KB Output is correct
15 Correct 5 ms 6656 KB Output is correct
16 Correct 6 ms 6656 KB Output is correct
17 Correct 5 ms 6656 KB Output is correct
18 Correct 5 ms 6656 KB Output is correct
19 Correct 5 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6656 KB Output is correct
2 Correct 5 ms 6656 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 6 ms 6656 KB Output is correct
5 Correct 7 ms 6656 KB Output is correct
6 Correct 5 ms 6656 KB Output is correct
7 Correct 5 ms 6656 KB Output is correct
8 Correct 5 ms 6656 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 5 ms 6656 KB Output is correct
11 Correct 5 ms 6656 KB Output is correct
12 Correct 5 ms 6656 KB Output is correct
13 Correct 5 ms 6656 KB Output is correct
14 Correct 6 ms 6784 KB Output is correct
15 Correct 5 ms 6656 KB Output is correct
16 Correct 6 ms 6656 KB Output is correct
17 Correct 5 ms 6656 KB Output is correct
18 Correct 5 ms 6656 KB Output is correct
19 Correct 5 ms 6656 KB Output is correct
20 Correct 642 ms 303128 KB Output is correct
21 Correct 633 ms 301432 KB Output is correct
22 Correct 72 ms 12408 KB Output is correct
23 Correct 74 ms 12408 KB Output is correct
24 Correct 446 ms 200440 KB Output is correct
25 Correct 310 ms 143608 KB Output is correct
26 Correct 298 ms 140792 KB Output is correct
27 Correct 315 ms 163576 KB Output is correct
28 Correct 431 ms 199160 KB Output is correct
29 Correct 309 ms 142328 KB Output is correct
30 Correct 291 ms 159056 KB Output is correct
31 Correct 301 ms 168524 KB Output is correct
32 Correct 592 ms 265472 KB Output is correct
33 Correct 894 ms 443632 KB Output is correct
34 Correct 583 ms 264312 KB Output is correct
35 Correct 575 ms 267512 KB Output is correct
36 Correct 854 ms 445944 KB Output is correct
37 Correct 560 ms 264056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 12532 KB Output is correct
2 Correct 96 ms 12024 KB Output is correct
3 Correct 83 ms 12024 KB Output is correct
4 Correct 82 ms 12024 KB Output is correct
5 Correct 73 ms 11384 KB Output is correct
6 Correct 81 ms 11512 KB Output is correct
7 Correct 81 ms 11640 KB Output is correct
8 Correct 70 ms 11384 KB Output is correct
9 Correct 73 ms 11388 KB Output is correct
10 Correct 68 ms 11384 KB Output is correct
11 Correct 74 ms 11384 KB Output is correct
12 Correct 78 ms 11384 KB Output is correct
13 Correct 82 ms 11384 KB Output is correct
14 Correct 86 ms 11384 KB Output is correct
15 Correct 84 ms 11380 KB Output is correct
16 Correct 85 ms 11384 KB Output is correct
17 Correct 76 ms 11512 KB Output is correct
18 Correct 67 ms 11384 KB Output is correct
19 Correct 5 ms 6656 KB Output is correct
20 Correct 5 ms 6656 KB Output is correct
21 Correct 5 ms 6656 KB Output is correct
22 Correct 6 ms 6656 KB Output is correct
23 Correct 7 ms 6656 KB Output is correct
24 Correct 5 ms 6656 KB Output is correct
25 Correct 5 ms 6656 KB Output is correct
26 Correct 5 ms 6656 KB Output is correct
27 Correct 5 ms 6656 KB Output is correct
28 Correct 5 ms 6656 KB Output is correct
29 Correct 5 ms 6656 KB Output is correct
30 Correct 5 ms 6656 KB Output is correct
31 Correct 5 ms 6656 KB Output is correct
32 Correct 6 ms 6784 KB Output is correct
33 Correct 5 ms 6656 KB Output is correct
34 Correct 6 ms 6656 KB Output is correct
35 Correct 5 ms 6656 KB Output is correct
36 Correct 5 ms 6656 KB Output is correct
37 Correct 5 ms 6656 KB Output is correct
38 Correct 642 ms 303128 KB Output is correct
39 Correct 633 ms 301432 KB Output is correct
40 Correct 72 ms 12408 KB Output is correct
41 Correct 74 ms 12408 KB Output is correct
42 Correct 446 ms 200440 KB Output is correct
43 Correct 310 ms 143608 KB Output is correct
44 Correct 298 ms 140792 KB Output is correct
45 Correct 315 ms 163576 KB Output is correct
46 Correct 431 ms 199160 KB Output is correct
47 Correct 309 ms 142328 KB Output is correct
48 Correct 291 ms 159056 KB Output is correct
49 Correct 301 ms 168524 KB Output is correct
50 Correct 592 ms 265472 KB Output is correct
51 Correct 894 ms 443632 KB Output is correct
52 Correct 583 ms 264312 KB Output is correct
53 Correct 575 ms 267512 KB Output is correct
54 Correct 854 ms 445944 KB Output is correct
55 Correct 560 ms 264056 KB Output is correct
56 Runtime error 1713 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Halted 0 ms 0 KB -