Submission #1012935

# Submission time Handle Problem Language Result Execution time Memory
1012935 2024-07-02T20:39:11 Z xnqs Lasers (NOI19_lasers) C++17
100 / 100
137 ms 15132 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>

int x, q;

std::vector<std::pair<int,int>> can_uncover(int n, int l, int offset) {
	std::vector<std::pair<int,int>> ret;
	if (l <= n/2) {
		ret.emplace_back(1,n);
	}
	else if (l < n) {
		ret.emplace_back(1,n-l);
		ret.emplace_back(n-(n-l)+1,n);
	}

	for (auto& [i, j] : ret) {
		i += offset;
		j += offset;
	}

	return ret;
}

std::vector<std::pair<int,int>> union_segments(std::vector<std::pair<int,int>> arr) {
	std::sort(arr.begin(),arr.end());

	std::vector<std::pair<int,int>> ret;
	for (const auto& [l, r] : arr) {
		if (ret.empty()||ret.back().second<l) {
			ret.emplace_back(l,r);
		}
		else {
			ret.back().second = std::max(ret.back().second,r);
		}
	}

	return ret;
}

std::vector<std::pair<int,int>> not_segments(std::vector<std::pair<int,int>> arr) {
	if (arr.empty()) {
		std::vector<std::pair<int,int>> ret;
		ret.emplace_back(1,x);
		return ret;
	}

	std::sort(arr.begin(),arr.end());

	std::vector<std::pair<int,int>> ret;
	if (arr[0].first>1) {
		ret.emplace_back(1,arr[0].first-1);
	}
	for (int i = 0; i < arr.size()-1; i++) {
		if (arr[i+1].first-arr[i].second>1) {
			ret.emplace_back(arr[i].second+1,arr[i+1].first-1);
		}
	}
	if (x-arr.back().second>=1) {
		ret.emplace_back(arr.back().second+1,x);
	}

	return ret;
}

int sum_segments(const std::vector<std::pair<int,int>>& arr) {
	int ret = 0;
	for (const auto& [l, r] : arr) {
		ret += r-l+1;
	}
	return ret;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	std::cin >> x >> q;

	std::vector<std::pair<int,int>> segments_covered;
	while (q--) {
		int n;
		std::cin >> n;

		std::vector<int> walls(n);
		for (auto& i : walls) {
			std::cin >> i;
		}

		int pfx = 0, sfx = std::accumulate(walls.begin(),walls.end(),0);
		std::vector<std::pair<int,int>> segments_uncovered;
		for (int i = 0; i < n; i++) {
			auto tmp = can_uncover(x-pfx,sfx,pfx);
			for (const auto& it : tmp) {
				segments_uncovered.emplace_back(it);
			}

			pfx += walls[i];
			sfx -= walls[i];
		}

		auto neg = not_segments(union_segments(segments_uncovered));
		for (const auto& it : neg) {
			segments_covered.emplace_back(it);
		}
	}

	segments_covered = union_segments(segments_covered);
	std::cout << sum_segments(segments_covered) << "\n";
}

Compilation message

lasers.cpp: In function 'std::vector<std::pair<int, int> > not_segments(std::vector<std::pair<int, int> >)':
lasers.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 0; i < arr.size()-1; i++) {
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 82 ms 13796 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 134 ms 9528 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10560 KB Output is correct
2 Correct 12 ms 3288 KB Output is correct
3 Correct 13 ms 2664 KB Output is correct
4 Correct 63 ms 12072 KB Output is correct
5 Correct 28 ms 7008 KB Output is correct
6 Correct 65 ms 13280 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 69 ms 15132 KB Output is correct
9 Correct 43 ms 6712 KB Output is correct
10 Correct 65 ms 12144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10560 KB Output is correct
2 Correct 12 ms 3288 KB Output is correct
3 Correct 13 ms 2664 KB Output is correct
4 Correct 63 ms 12072 KB Output is correct
5 Correct 28 ms 7008 KB Output is correct
6 Correct 65 ms 13280 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 69 ms 15132 KB Output is correct
9 Correct 43 ms 6712 KB Output is correct
10 Correct 65 ms 12144 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 125 ms 8660 KB Output is correct
22 Correct 22 ms 1984 KB Output is correct
23 Correct 16 ms 2908 KB Output is correct
24 Correct 78 ms 7500 KB Output is correct
25 Correct 121 ms 8644 KB Output is correct
26 Correct 46 ms 3672 KB Output is correct
27 Correct 20 ms 1772 KB Output is correct
28 Correct 122 ms 8652 KB Output is correct
29 Correct 127 ms 8772 KB Output is correct
30 Correct 54 ms 6064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 82 ms 13796 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 134 ms 9528 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 58 ms 10560 KB Output is correct
22 Correct 12 ms 3288 KB Output is correct
23 Correct 13 ms 2664 KB Output is correct
24 Correct 63 ms 12072 KB Output is correct
25 Correct 28 ms 7008 KB Output is correct
26 Correct 65 ms 13280 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 69 ms 15132 KB Output is correct
29 Correct 43 ms 6712 KB Output is correct
30 Correct 65 ms 12144 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 0 ms 460 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 125 ms 8660 KB Output is correct
42 Correct 22 ms 1984 KB Output is correct
43 Correct 16 ms 2908 KB Output is correct
44 Correct 78 ms 7500 KB Output is correct
45 Correct 121 ms 8644 KB Output is correct
46 Correct 46 ms 3672 KB Output is correct
47 Correct 20 ms 1772 KB Output is correct
48 Correct 122 ms 8652 KB Output is correct
49 Correct 127 ms 8772 KB Output is correct
50 Correct 54 ms 6064 KB Output is correct
51 Correct 21 ms 2916 KB Output is correct
52 Correct 129 ms 9800 KB Output is correct
53 Correct 126 ms 9748 KB Output is correct
54 Correct 33 ms 3024 KB Output is correct
55 Correct 77 ms 6780 KB Output is correct
56 Correct 55 ms 6000 KB Output is correct
57 Correct 52 ms 4764 KB Output is correct
58 Correct 137 ms 9920 KB Output is correct
59 Correct 42 ms 3520 KB Output is correct
60 Correct 65 ms 4700 KB Output is correct