Submission #261267

# Submission time Handle Problem Language Result Execution time Memory
261267 2020-08-11T15:39:45 Z Saboon Treatment Project (JOI20_treatment) C++14
9 / 100
3000 ms 6900 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];

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;
	memset(dp, -1, sizeof dp);
	for (ll _ = 0; _ < m; _++){
		for (ll iit = 1; iit <= m; iit++){
			ll i = p[iit];
			if (L[i] == 1)
				dp[i] = C[i];
			for (ll jit = 1; jit <= m; jit++){
				ll j = p[jit];
				if (L[j] <= R[j] and abs(T[i]-T[j]) <= R[j]-L[i]+1 and dp[j] != -1)
					if (dp[i] == -1 or dp[i] > dp[j] + C[i])
						dp[i] = dp[j] + C[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;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:38:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (hi == S.size())
        ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 92 ms 6900 KB Output is correct
2 Correct 86 ms 6320 KB Output is correct
3 Correct 82 ms 6476 KB Output is correct
4 Correct 81 ms 6392 KB Output is correct
5 Correct 70 ms 5752 KB Output is correct
6 Correct 74 ms 5752 KB Output is correct
7 Correct 79 ms 5880 KB Output is correct
8 Correct 67 ms 5752 KB Output is correct
9 Correct 75 ms 5752 KB Output is correct
10 Correct 65 ms 5752 KB Output is correct
11 Correct 70 ms 5624 KB Output is correct
12 Correct 73 ms 5628 KB Output is correct
13 Correct 79 ms 5752 KB Output is correct
14 Correct 79 ms 5756 KB Output is correct
15 Correct 80 ms 5752 KB Output is correct
16 Correct 81 ms 5752 KB Output is correct
17 Correct 73 ms 5752 KB Output is correct
18 Correct 64 ms 5752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 2 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 2 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Execution timed out 3090 ms 2176 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 6900 KB Output is correct
2 Correct 86 ms 6320 KB Output is correct
3 Correct 82 ms 6476 KB Output is correct
4 Correct 81 ms 6392 KB Output is correct
5 Correct 70 ms 5752 KB Output is correct
6 Correct 74 ms 5752 KB Output is correct
7 Correct 79 ms 5880 KB Output is correct
8 Correct 67 ms 5752 KB Output is correct
9 Correct 75 ms 5752 KB Output is correct
10 Correct 65 ms 5752 KB Output is correct
11 Correct 70 ms 5624 KB Output is correct
12 Correct 73 ms 5628 KB Output is correct
13 Correct 79 ms 5752 KB Output is correct
14 Correct 79 ms 5756 KB Output is correct
15 Correct 80 ms 5752 KB Output is correct
16 Correct 81 ms 5752 KB Output is correct
17 Correct 73 ms 5752 KB Output is correct
18 Correct 64 ms 5752 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1920 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 2 ms 1920 KB Output is correct
28 Correct 2 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 2 ms 1920 KB Output is correct
31 Correct 2 ms 1920 KB Output is correct
32 Correct 2 ms 1920 KB Output is correct
33 Correct 2 ms 1920 KB Output is correct
34 Correct 2 ms 1920 KB Output is correct
35 Correct 2 ms 1920 KB Output is correct
36 Correct 2 ms 1920 KB Output is correct
37 Correct 2 ms 1920 KB Output is correct
38 Execution timed out 3090 ms 2176 KB Time limit exceeded
39 Halted 0 ms 0 KB -