Submission #300231

# Submission time Handle Problem Language Result Execution time Memory
300231 2020-09-17T01:53:43 Z Elegia Carnival Tickets (IOI20_tickets) C++17
100 / 100
1016 ms 90272 KB
#include "tickets.h"
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <iostream>

using namespace std;

long long find_maximum(int k, vector<vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	vector<vector<int>> sgn(n, vector<int>(m));
	vector<pair<int, pair<int, int>>> profit;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < k; ++j) {
			sgn[i][j] = -1;
			profit.emplace_back(x[i][j] + x[i][j + m - k], make_pair(i, j));
		}
	}
	nth_element(profit.begin(), profit.begin() + n * k / 2, profit.end());
	for (int i = n * k / 2; i < n * k; ++i) {
		int u, v;
		tie(u, v) = profit[i].second;
		++sgn[u][v];
		++sgn[u][v + m - k];
	}
	long long ret = 0;
	vector<queue<int>> pos(n), neg(n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (sgn[i][j] > 0) {
				pos[i].push(j);
				ret += x[i][j];
			} else if (sgn[i][j] < 0) {
				neg[i].push(j);
				ret -= x[i][j];
			}
		}
	}
	vector<int> level(n, -1);
	vector<vector<int>> answer(n, vector<int>(m, -1));
	for (int rep = 0; rep < k; ++rep) {
		int val = 0;
		for (int i = 0; i < n; ++i) {
			if (pos[i].empty()) {
				--val;
				answer[i][neg[i].front()] = rep;
				neg[i].pop();
				level[i] = rep;
			} else if (neg[i].empty()) {
				++val;
				answer[i][pos[i].front()] = rep;
				pos[i].pop();
				level[i] = rep;
			}
		}
		for (int i = 0; i < n; ++i) {
			if (level[i] == rep) continue;
			if (val < 0) {
				++val;
				answer[i][pos[i].front()] = rep;
				pos[i].pop();
			} else {
				--val;
				answer[i][neg[i].front()] = rep;
				neg[i].pop();
			}
		}
	}
	allocate_tickets(answer);
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 34 ms 3192 KB Output is correct
6 Correct 733 ms 62488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 25 ms 3620 KB Output is correct
6 Correct 636 ms 71984 KB Output is correct
7 Correct 683 ms 77584 KB Output is correct
8 Correct 3 ms 832 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 7 ms 1216 KB Output is correct
13 Correct 22 ms 3448 KB Output is correct
14 Correct 21 ms 3196 KB Output is correct
15 Correct 712 ms 83120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 56 ms 4204 KB Output is correct
6 Correct 6 ms 968 KB Output is correct
7 Correct 12 ms 3136 KB Output is correct
8 Correct 928 ms 88720 KB Output is correct
9 Correct 877 ms 84304 KB Output is correct
10 Correct 1016 ms 84280 KB Output is correct
11 Correct 953 ms 90272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct
13 Correct 34 ms 3192 KB Output is correct
14 Correct 43 ms 3192 KB Output is correct
15 Correct 34 ms 3448 KB Output is correct
16 Correct 48 ms 4212 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 4 ms 1024 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 26 ms 3552 KB Output is correct
21 Correct 31 ms 3580 KB Output is correct
22 Correct 33 ms 3988 KB Output is correct
23 Correct 33 ms 3952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 34 ms 3192 KB Output is correct
12 Correct 733 ms 62488 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 25 ms 3620 KB Output is correct
18 Correct 636 ms 71984 KB Output is correct
19 Correct 683 ms 77584 KB Output is correct
20 Correct 3 ms 832 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 7 ms 1216 KB Output is correct
25 Correct 22 ms 3448 KB Output is correct
26 Correct 21 ms 3196 KB Output is correct
27 Correct 712 ms 83120 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 56 ms 4204 KB Output is correct
33 Correct 6 ms 968 KB Output is correct
34 Correct 12 ms 3136 KB Output is correct
35 Correct 928 ms 88720 KB Output is correct
36 Correct 877 ms 84304 KB Output is correct
37 Correct 1016 ms 84280 KB Output is correct
38 Correct 953 ms 90272 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 3 ms 640 KB Output is correct
41 Correct 3 ms 640 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 3 ms 640 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 512 KB Output is correct
47 Correct 3 ms 688 KB Output is correct
48 Correct 5 ms 640 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 4 ms 640 KB Output is correct
51 Correct 34 ms 3192 KB Output is correct
52 Correct 43 ms 3192 KB Output is correct
53 Correct 34 ms 3448 KB Output is correct
54 Correct 48 ms 4212 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 4 ms 1024 KB Output is correct
57 Correct 2 ms 896 KB Output is correct
58 Correct 26 ms 3552 KB Output is correct
59 Correct 31 ms 3580 KB Output is correct
60 Correct 33 ms 3988 KB Output is correct
61 Correct 33 ms 3952 KB Output is correct
62 Correct 82 ms 7712 KB Output is correct
63 Correct 118 ms 7800 KB Output is correct
64 Correct 152 ms 10604 KB Output is correct
65 Correct 353 ms 32604 KB Output is correct
66 Correct 409 ms 40504 KB Output is correct
67 Correct 11 ms 3136 KB Output is correct
68 Correct 6 ms 840 KB Output is correct
69 Correct 895 ms 62236 KB Output is correct
70 Correct 864 ms 72284 KB Output is correct
71 Correct 952 ms 88744 KB Output is correct
72 Correct 777 ms 86080 KB Output is correct
73 Correct 913 ms 84976 KB Output is correct
74 Correct 677 ms 71864 KB Output is correct
75 Correct 846 ms 71344 KB Output is correct