답안 #499257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499257 2021-12-27T14:17:31 Z dennisstar Shopping Plans (CCO20_day2problem3) C++17
25 / 25
299 ms 48496 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int INF = 1e9;

struct dt {
	int i, cur, use, lst, sk, in;
	dt(int i=0, int c=0, int u=0, int l=0, int sk=0, int in=0) : i(i), cur(c), use(u), lst(l), sk(sk), in(in) {}
	bool operator <(dt p) const {
		return i<p.i;
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int n, m, k;
	cin>>n>>m>>k;
	vector<vector<int>> v(m);
	vector<int> s(m), e(m);
	ll mn=0;
	for (int i=0, a, b; i<n; i++) cin>>a>>b, v[a-1].emplace_back(b);
	for (int i=0; i<m; i++) {
		cin>>s[i]>>e[i];
		if (v[i].size()<s[i]) {
			while (k--) cout<<"-1\n";
			return 0;
		}
		sort(v[i].begin(), v[i].end());
		for (int j=0; j<s[i]; j++) mn+=v[i][j];
	}

	vector<int> in(m);
	for (int i=0; i<m; i++) in[i]=i;
	auto get = [&](int i) { return s[i]?v[i][s[i]-1]:0; };
	sort(in.begin(), in.end(), [&](int x, int y) {
		return (e[x]&&s[x]<v[x].size()?(v[x][s[x]]-get(x)):INF)
			< (e[y]&&s[y]<v[y].size()?(v[y][s[y]]-get(y)):INF);
	});

	priority_queue<pair<ll, dt>> pq;
	if (s[in[0]]) pq.emplace(-mn, dt(0, s[in[0]]-1, 1, v[in[0]].size(), 0, 1));
	else pq.emplace(-mn-v[in[0]][0], dt(0, 0, 1, v[in[0]].size(), 1)), k--, cout<<mn<<'\n';
	while (pq.size()&&k) {
		auto [cost, d]=pq.top();
		pq.pop();
		cout<<-cost<<'\n';
		k--;

		int i=in[d.i];
		int ni=d.i+1<m?in[d.i+1]:-1;

		if (!d.in&&ni!=-1&&s[ni]!=v[ni].size()&&e[ni]) {
			dt nxt(d.i+1, s[ni], 1, v[ni].size(), 1);
			if (d.sk) pq.emplace(cost-v[ni][s[ni]]+get(ni)+v[i][s[i]]-get(i), nxt);
			pq.emplace(cost-v[ni][s[ni]]+get(ni), nxt);
		}
		
		if (d.cur+1<d.lst) pq.emplace(cost-v[i][d.cur+1]+v[i][d.cur], dt(d.i, d.cur+1, d.use, d.lst, d.in));
		if (s[i]<=d.use&&d.use<e[i]&&d.cur) pq.emplace(cost-v[i][0], dt(d.i, 0, d.use+1, d.cur, 0));
		if (d.use<s[i]&&s[i]-d.use<d.cur) pq.emplace(cost-v[i][s[i]-d.use]+v[i][s[i]-d.use-1], dt(d.i, s[i]-d.use, d.use+1, d.cur, 0));
	}

	while (k--) cout<<"-1\n";

	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:27:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   27 |   if (v[i].size()<s[i]) {
Main.cpp: In lambda function:
Main.cpp:39:21: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   return (e[x]&&s[x]<v[x].size()?(v[x][s[x]]-get(x)):INF)
Main.cpp:40:17: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |    < (e[y]&&s[y]<v[y].size()?(v[y][s[y]]-get(y)):INF);
Main.cpp: In function 'int main()':
Main.cpp:55:27: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   if (!d.in&&ni!=-1&&s[ni]!=v[ni].size()&&e[ni]) {
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 844 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 3 ms 844 KB Output is correct
6 Correct 5 ms 844 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 3 ms 848 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 3 ms 848 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 3 ms 844 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 716 KB Output is correct
23 Correct 2 ms 716 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 844 KB Output is correct
27 Correct 2 ms 716 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 18328 KB Output is correct
2 Correct 67 ms 18152 KB Output is correct
3 Correct 96 ms 18120 KB Output is correct
4 Correct 80 ms 18120 KB Output is correct
5 Correct 60 ms 10004 KB Output is correct
6 Correct 67 ms 9804 KB Output is correct
7 Correct 68 ms 17856 KB Output is correct
8 Correct 64 ms 17736 KB Output is correct
9 Correct 6 ms 844 KB Output is correct
10 Correct 66 ms 18136 KB Output is correct
11 Correct 6 ms 1012 KB Output is correct
12 Correct 35 ms 1864 KB Output is correct
13 Correct 74 ms 17884 KB Output is correct
14 Correct 69 ms 18248 KB Output is correct
15 Correct 6 ms 972 KB Output is correct
16 Correct 67 ms 17752 KB Output is correct
17 Correct 90 ms 18020 KB Output is correct
18 Correct 16 ms 1480 KB Output is correct
19 Correct 74 ms 18204 KB Output is correct
20 Correct 69 ms 18560 KB Output is correct
21 Correct 7 ms 972 KB Output is correct
22 Correct 65 ms 9172 KB Output is correct
23 Correct 63 ms 17420 KB Output is correct
24 Correct 6 ms 1104 KB Output is correct
25 Correct 6 ms 1100 KB Output is correct
26 Correct 66 ms 9728 KB Output is correct
27 Correct 61 ms 9764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 844 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 3 ms 844 KB Output is correct
6 Correct 5 ms 844 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 3 ms 848 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 3 ms 848 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 3 ms 844 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 716 KB Output is correct
23 Correct 2 ms 716 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 844 KB Output is correct
27 Correct 2 ms 716 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 62 ms 18328 KB Output is correct
30 Correct 67 ms 18152 KB Output is correct
31 Correct 96 ms 18120 KB Output is correct
32 Correct 80 ms 18120 KB Output is correct
33 Correct 60 ms 10004 KB Output is correct
34 Correct 67 ms 9804 KB Output is correct
35 Correct 68 ms 17856 KB Output is correct
36 Correct 64 ms 17736 KB Output is correct
37 Correct 6 ms 844 KB Output is correct
38 Correct 66 ms 18136 KB Output is correct
39 Correct 6 ms 1012 KB Output is correct
40 Correct 35 ms 1864 KB Output is correct
41 Correct 74 ms 17884 KB Output is correct
42 Correct 69 ms 18248 KB Output is correct
43 Correct 6 ms 972 KB Output is correct
44 Correct 67 ms 17752 KB Output is correct
45 Correct 90 ms 18020 KB Output is correct
46 Correct 16 ms 1480 KB Output is correct
47 Correct 74 ms 18204 KB Output is correct
48 Correct 69 ms 18560 KB Output is correct
49 Correct 7 ms 972 KB Output is correct
50 Correct 65 ms 9172 KB Output is correct
51 Correct 63 ms 17420 KB Output is correct
52 Correct 6 ms 1104 KB Output is correct
53 Correct 6 ms 1100 KB Output is correct
54 Correct 66 ms 9728 KB Output is correct
55 Correct 61 ms 9764 KB Output is correct
56 Correct 196 ms 28224 KB Output is correct
57 Correct 197 ms 24540 KB Output is correct
58 Correct 191 ms 25856 KB Output is correct
59 Correct 150 ms 22708 KB Output is correct
60 Correct 187 ms 20500 KB Output is correct
61 Correct 180 ms 25532 KB Output is correct
62 Correct 132 ms 20820 KB Output is correct
63 Correct 114 ms 18816 KB Output is correct
64 Correct 87 ms 3172 KB Output is correct
65 Correct 173 ms 24708 KB Output is correct
66 Correct 53 ms 6104 KB Output is correct
67 Correct 59 ms 4364 KB Output is correct
68 Correct 73 ms 18720 KB Output is correct
69 Correct 196 ms 25760 KB Output is correct
70 Correct 8 ms 1228 KB Output is correct
71 Correct 85 ms 18692 KB Output is correct
72 Correct 138 ms 22692 KB Output is correct
73 Correct 5 ms 972 KB Output is correct
74 Correct 65 ms 11000 KB Output is correct
75 Correct 233 ms 28608 KB Output is correct
76 Correct 6 ms 932 KB Output is correct
77 Correct 60 ms 9696 KB Output is correct
78 Correct 117 ms 19052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 2940 KB Output is correct
2 Correct 38 ms 1740 KB Output is correct
3 Correct 7 ms 972 KB Output is correct
4 Correct 8 ms 1136 KB Output is correct
5 Correct 244 ms 28916 KB Output is correct
6 Correct 197 ms 27736 KB Output is correct
7 Correct 201 ms 28204 KB Output is correct
8 Correct 203 ms 27384 KB Output is correct
9 Correct 204 ms 29148 KB Output is correct
10 Correct 203 ms 27596 KB Output is correct
11 Correct 179 ms 26236 KB Output is correct
12 Correct 141 ms 26268 KB Output is correct
13 Correct 124 ms 10732 KB Output is correct
14 Correct 201 ms 27752 KB Output is correct
15 Correct 192 ms 27684 KB Output is correct
16 Correct 70 ms 10164 KB Output is correct
17 Correct 71 ms 18292 KB Output is correct
18 Correct 261 ms 28048 KB Output is correct
19 Correct 81 ms 18592 KB Output is correct
20 Correct 74 ms 18148 KB Output is correct
21 Correct 184 ms 27260 KB Output is correct
22 Correct 62 ms 10020 KB Output is correct
23 Correct 80 ms 18276 KB Output is correct
24 Correct 238 ms 29004 KB Output is correct
25 Correct 72 ms 18696 KB Output is correct
26 Correct 65 ms 18580 KB Output is correct
27 Correct 158 ms 25816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 844 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 3 ms 844 KB Output is correct
6 Correct 5 ms 844 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 3 ms 848 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 3 ms 848 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 3 ms 844 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 716 KB Output is correct
23 Correct 2 ms 716 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 844 KB Output is correct
27 Correct 2 ms 716 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 62 ms 18328 KB Output is correct
30 Correct 67 ms 18152 KB Output is correct
31 Correct 96 ms 18120 KB Output is correct
32 Correct 80 ms 18120 KB Output is correct
33 Correct 60 ms 10004 KB Output is correct
34 Correct 67 ms 9804 KB Output is correct
35 Correct 68 ms 17856 KB Output is correct
36 Correct 64 ms 17736 KB Output is correct
37 Correct 6 ms 844 KB Output is correct
38 Correct 66 ms 18136 KB Output is correct
39 Correct 6 ms 1012 KB Output is correct
40 Correct 35 ms 1864 KB Output is correct
41 Correct 74 ms 17884 KB Output is correct
42 Correct 69 ms 18248 KB Output is correct
43 Correct 6 ms 972 KB Output is correct
44 Correct 67 ms 17752 KB Output is correct
45 Correct 90 ms 18020 KB Output is correct
46 Correct 16 ms 1480 KB Output is correct
47 Correct 74 ms 18204 KB Output is correct
48 Correct 69 ms 18560 KB Output is correct
49 Correct 7 ms 972 KB Output is correct
50 Correct 65 ms 9172 KB Output is correct
51 Correct 63 ms 17420 KB Output is correct
52 Correct 6 ms 1104 KB Output is correct
53 Correct 6 ms 1100 KB Output is correct
54 Correct 66 ms 9728 KB Output is correct
55 Correct 61 ms 9764 KB Output is correct
56 Correct 196 ms 28224 KB Output is correct
57 Correct 197 ms 24540 KB Output is correct
58 Correct 191 ms 25856 KB Output is correct
59 Correct 150 ms 22708 KB Output is correct
60 Correct 187 ms 20500 KB Output is correct
61 Correct 180 ms 25532 KB Output is correct
62 Correct 132 ms 20820 KB Output is correct
63 Correct 114 ms 18816 KB Output is correct
64 Correct 87 ms 3172 KB Output is correct
65 Correct 173 ms 24708 KB Output is correct
66 Correct 53 ms 6104 KB Output is correct
67 Correct 59 ms 4364 KB Output is correct
68 Correct 73 ms 18720 KB Output is correct
69 Correct 196 ms 25760 KB Output is correct
70 Correct 8 ms 1228 KB Output is correct
71 Correct 85 ms 18692 KB Output is correct
72 Correct 138 ms 22692 KB Output is correct
73 Correct 5 ms 972 KB Output is correct
74 Correct 65 ms 11000 KB Output is correct
75 Correct 233 ms 28608 KB Output is correct
76 Correct 6 ms 932 KB Output is correct
77 Correct 60 ms 9696 KB Output is correct
78 Correct 117 ms 19052 KB Output is correct
79 Correct 46 ms 2940 KB Output is correct
80 Correct 38 ms 1740 KB Output is correct
81 Correct 7 ms 972 KB Output is correct
82 Correct 8 ms 1136 KB Output is correct
83 Correct 244 ms 28916 KB Output is correct
84 Correct 197 ms 27736 KB Output is correct
85 Correct 201 ms 28204 KB Output is correct
86 Correct 203 ms 27384 KB Output is correct
87 Correct 204 ms 29148 KB Output is correct
88 Correct 203 ms 27596 KB Output is correct
89 Correct 179 ms 26236 KB Output is correct
90 Correct 141 ms 26268 KB Output is correct
91 Correct 124 ms 10732 KB Output is correct
92 Correct 201 ms 27752 KB Output is correct
93 Correct 192 ms 27684 KB Output is correct
94 Correct 70 ms 10164 KB Output is correct
95 Correct 71 ms 18292 KB Output is correct
96 Correct 261 ms 28048 KB Output is correct
97 Correct 81 ms 18592 KB Output is correct
98 Correct 74 ms 18148 KB Output is correct
99 Correct 184 ms 27260 KB Output is correct
100 Correct 62 ms 10020 KB Output is correct
101 Correct 80 ms 18276 KB Output is correct
102 Correct 238 ms 29004 KB Output is correct
103 Correct 72 ms 18696 KB Output is correct
104 Correct 65 ms 18580 KB Output is correct
105 Correct 158 ms 25816 KB Output is correct
106 Correct 40 ms 1500 KB Output is correct
107 Correct 58 ms 3208 KB Output is correct
108 Correct 44 ms 2104 KB Output is correct
109 Correct 60 ms 3000 KB Output is correct
110 Correct 242 ms 33952 KB Output is correct
111 Correct 236 ms 33032 KB Output is correct
112 Correct 256 ms 32824 KB Output is correct
113 Correct 193 ms 31912 KB Output is correct
114 Correct 273 ms 34140 KB Output is correct
115 Correct 240 ms 32672 KB Output is correct
116 Correct 197 ms 48496 KB Output is correct
117 Correct 159 ms 30780 KB Output is correct
118 Correct 178 ms 16820 KB Output is correct
119 Correct 99 ms 13420 KB Output is correct
120 Correct 257 ms 32396 KB Output is correct
121 Correct 84 ms 18704 KB Output is correct
122 Correct 94 ms 18608 KB Output is correct
123 Correct 299 ms 32888 KB Output is correct
124 Correct 71 ms 10712 KB Output is correct
125 Correct 96 ms 18360 KB Output is correct
126 Correct 215 ms 32264 KB Output is correct
127 Correct 69 ms 9848 KB Output is correct
128 Correct 75 ms 18940 KB Output is correct
129 Correct 270 ms 34480 KB Output is correct
130 Correct 87 ms 18528 KB Output is correct
131 Correct 84 ms 18416 KB Output is correct
132 Correct 167 ms 30944 KB Output is correct