Submission #1050763

# Submission time Handle Problem Language Result Execution time Memory
1050763 2024-08-09T14:03:02 Z Huseyn123 Carnival Tickets (IOI20_tickets) C++17
100 / 100
515 ms 54352 KB
#include <bits/stdc++.h> 
#pragma GCC optimize("O3,unroll-loops")
#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 1 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 1 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 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 1 ms 348 KB Output is correct
5 Correct 11 ms 2296 KB Output is correct
6 Correct 265 ms 51536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 11 ms 2396 KB Output is correct
6 Correct 284 ms 52388 KB Output is correct
7 Correct 296 ms 52820 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 4 ms 860 KB Output is correct
13 Correct 12 ms 2140 KB Output is correct
14 Correct 10 ms 2140 KB Output is correct
15 Correct 308 ms 53428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 18 ms 2576 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 4 ms 984 KB Output is correct
8 Correct 502 ms 54316 KB Output is correct
9 Correct 474 ms 50748 KB Output is correct
10 Correct 462 ms 50768 KB Output is correct
11 Correct 515 ms 54348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 520 KB Output is correct
13 Correct 11 ms 2396 KB Output is correct
14 Correct 11 ms 2424 KB Output is correct
15 Correct 15 ms 2396 KB Output is correct
16 Correct 18 ms 2396 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 15 ms 2396 KB Output is correct
21 Correct 15 ms 2392 KB Output is correct
22 Correct 17 ms 2368 KB Output is correct
23 Correct 21 ms 2384 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
11 Correct 11 ms 2296 KB Output is correct
12 Correct 265 ms 51536 KB Output is correct
13 Correct 0 ms 344 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 348 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
18 Correct 284 ms 52388 KB Output is correct
19 Correct 296 ms 52820 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 4 ms 860 KB Output is correct
25 Correct 12 ms 2140 KB Output is correct
26 Correct 10 ms 2140 KB Output is correct
27 Correct 308 ms 53428 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 18 ms 2576 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 4 ms 984 KB Output is correct
35 Correct 502 ms 54316 KB Output is correct
36 Correct 474 ms 50748 KB Output is correct
37 Correct 462 ms 50768 KB Output is correct
38 Correct 515 ms 54348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 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 348 KB Output is correct
48 Correct 2 ms 348 KB Output is correct
49 Correct 2 ms 348 KB Output is correct
50 Correct 1 ms 520 KB Output is correct
51 Correct 11 ms 2396 KB Output is correct
52 Correct 11 ms 2424 KB Output is correct
53 Correct 15 ms 2396 KB Output is correct
54 Correct 18 ms 2396 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 15 ms 2396 KB Output is correct
59 Correct 15 ms 2392 KB Output is correct
60 Correct 17 ms 2368 KB Output is correct
61 Correct 21 ms 2384 KB Output is correct
62 Correct 32 ms 5968 KB Output is correct
63 Correct 30 ms 5976 KB Output is correct
64 Correct 51 ms 6224 KB Output is correct
65 Correct 184 ms 23420 KB Output is correct
66 Correct 209 ms 24144 KB Output is correct
67 Correct 4 ms 856 KB Output is correct
68 Correct 3 ms 604 KB Output is correct
69 Correct 269 ms 51472 KB Output is correct
70 Correct 385 ms 52564 KB Output is correct
71 Correct 488 ms 54352 KB Output is correct
72 Correct 406 ms 52268 KB Output is correct
73 Correct 473 ms 52304 KB Output is correct
74 Correct 309 ms 50772 KB Output is correct
75 Correct 376 ms 50772 KB Output is correct