Submission #482835

# Submission time Handle Problem Language Result Execution time Memory
482835 2021-10-26T13:56:01 Z glome Stove (JOI18_stove) C++17
100 / 100
68 ms 7148 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<pair<int, int>> d;
	vector<int> y(n);
	for (int i = 0; i<n; i++) {
		cin >> y[i];
	}
	for (int i = 0; i<n-1; i++) {
		if(y[i] + 1 == y[i + 1]) {
			continue;
		}
		d.push_back({y[i] + 1, y[i+1] - 1});
	}
	sort(d.begin(), d.end(), [&] (pair<int, int> A, pair<int, int> B) {
		return A.second - A.first > B.second - B.first;
	});
	map<int, bool> mark;
	for (int i = k - 1; i<d.size(); i++) {
		mark[d[i].first - 1] = 1;
	}
	int ans = 0;
	for (int i = 0; i<n - 1; i++) {
		if(mark[y[i]]) {
			if(i == 0) {
				ans += (y[i + 1] + 1) - y[i];
				continue;
			}
			if(mark[y[i-1]]) {
				ans += y[i + 1] - y[i];
			}
			else {
				ans +=( y[i + 1] + 1) - y[i];
			}
		}
		else {
			if(i == 0) {
				ans++;
				continue;
			}
			if(!mark[y[i-1]]) {
				ans++;
			}
		}
	}
	if(n == 1) {
		ans++;
	}
	if(n >= 2) {
		if(!mark[y[n-2]]) {
			ans++;
		}
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i = k - 1; i<d.size(); i++) {
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 68 ms 7092 KB Output is correct
17 Correct 58 ms 7112 KB Output is correct
18 Correct 59 ms 7056 KB Output is correct
19 Correct 58 ms 7076 KB Output is correct
20 Correct 48 ms 7108 KB Output is correct
21 Correct 41 ms 7092 KB Output is correct
22 Correct 39 ms 7080 KB Output is correct
23 Correct 40 ms 7148 KB Output is correct
24 Correct 41 ms 7072 KB Output is correct