Submission #1050760

# Submission time Handle Problem Language Result Execution time Memory
1050760 2024-08-09T14:00:07 Z Huseyn123 Carnival Tickets (IOI20_tickets) C++17
100 / 100
526 ms 65880 KB
#include <bits/stdc++.h> 
#include "tickets.h"
#include <vector>
#define pb push_back
using namespace std; 
typedef long long ll; 
ll find_maximum(int k, vector<vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	ll res=0;
	vector<vector<int>> answer; 
	for(int i=0;i<n;i++){
		vector<int> d; 
		for(int j=0;j<m;j++){
			d.pb(-1);
		}
		answer.pb(d);
	}
	int pre[n],suf[n];
	for(int i=0;i<n;i++){
		pre[i]=k; 
		suf[i]=0;
		for(int j=0;j<k;j++){
			res-=x[i][j]; 
		}
	}
	set<pair<ll,int>> c;
	for(int i=0;i<n;i++){
		if(pre[i]==0){
			continue;
		}
		ll val=x[i][m-suf[i]-1]+x[i][pre[i]-1];
		c.insert({val,i});
	}
	for(int i=0;i<k*(n/2);i++){
		pair<ll,int> p=*(--c.end());
		c.erase(p);
		res+=p.first;
		int j=p.second;
		pre[j]--;
		suf[j]++;
		if(pre[j]==0){
			continue;
		}
		ll val=x[j][m-suf[j]-1]+x[j][pre[j]-1];
		c.insert({val,j});
	}
	for(int i=0;i<k;i++){
		vector<pair<int,int>> d;
		for(int j=0;j<n;j++){
			d.pb({suf[j],j});
		}
		sort(d.rbegin(),d.rend());
		for(int j=0;j<n/2;j++){
			answer[d[j].second][m-d[j].first]=i;
			suf[d[j].second]--;
		}
		for(int j=n/2;j<n;j++){
			answer[d[j].second][pre[d[j].second]-1]=i;
			pre[d[j].second]--;
		}
	}
	allocate_tickets(answer);
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 11 ms 3296 KB Output is correct
6 Correct 298 ms 63084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 416 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 12 ms 2652 KB Output is correct
6 Correct 277 ms 55068 KB Output is correct
7 Correct 304 ms 55376 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 14 ms 2124 KB Output is correct
14 Correct 15 ms 2312 KB Output is correct
15 Correct 325 ms 56072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 18 ms 3348 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 4 ms 1116 KB Output is correct
8 Correct 503 ms 65880 KB Output is correct
9 Correct 496 ms 61400 KB Output is correct
10 Correct 483 ms 61540 KB Output is correct
11 Correct 520 ms 65772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 12 ms 3056 KB Output is correct
14 Correct 12 ms 3204 KB Output is correct
15 Correct 16 ms 3080 KB Output is correct
16 Correct 19 ms 3156 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 15 ms 2800 KB Output is correct
21 Correct 18 ms 3164 KB Output is correct
22 Correct 16 ms 2656 KB Output is correct
23 Correct 18 ms 3040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 860 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 1 ms 604 KB Output is correct
11 Correct 11 ms 3296 KB Output is correct
12 Correct 298 ms 63084 KB Output is correct
13 Correct 0 ms 416 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 444 KB Output is correct
17 Correct 12 ms 2652 KB Output is correct
18 Correct 277 ms 55068 KB Output is correct
19 Correct 304 ms 55376 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 14 ms 2124 KB Output is correct
26 Correct 15 ms 2312 KB Output is correct
27 Correct 325 ms 56072 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 18 ms 3348 KB Output is correct
33 Correct 3 ms 860 KB Output is correct
34 Correct 4 ms 1116 KB Output is correct
35 Correct 503 ms 65880 KB Output is correct
36 Correct 496 ms 61400 KB Output is correct
37 Correct 483 ms 61540 KB Output is correct
38 Correct 520 ms 65772 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 600 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 2 ms 588 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 600 KB Output is correct
51 Correct 12 ms 3056 KB Output is correct
52 Correct 12 ms 3204 KB Output is correct
53 Correct 16 ms 3080 KB Output is correct
54 Correct 19 ms 3156 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 512 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 15 ms 2800 KB Output is correct
59 Correct 18 ms 3164 KB Output is correct
60 Correct 16 ms 2656 KB Output is correct
61 Correct 18 ms 3040 KB Output is correct
62 Correct 30 ms 7628 KB Output is correct
63 Correct 31 ms 7508 KB Output is correct
64 Correct 53 ms 7760 KB Output is correct
65 Correct 171 ms 28752 KB Output is correct
66 Correct 222 ms 29268 KB Output is correct
67 Correct 6 ms 1112 KB Output is correct
68 Correct 3 ms 860 KB Output is correct
69 Correct 272 ms 62616 KB Output is correct
70 Correct 396 ms 63628 KB Output is correct
71 Correct 526 ms 65572 KB Output is correct
72 Correct 379 ms 56656 KB Output is correct
73 Correct 477 ms 63312 KB Output is correct
74 Correct 318 ms 55120 KB Output is correct
75 Correct 391 ms 61848 KB Output is correct