#include<bits/stdc++.h>
#include "tickets.h"
#define ll long long
using namespace std;
ll N,M,K,vred=0,pok[1505];
vector<vector<int>> kako,koliko;
struct slog{
int gde;
ll dob;
bool operator < (const slog &a) const{
return dob<a.dob;
}
}pp;
vector<int> p[1505],m[1505];
int niz[1505];
bool cmp(int a,int b){
return p[a].size()<p[b].size();
}
priority_queue<slog> PQ;
void stavi(int gde){
if(pok[gde]<0)
return;
pp.gde=gde;
pp.dob=koliko[gde][pok[gde]]+koliko[gde][pok[gde]+M-K];
PQ.push(pp);
return;
}
ll find_maximum(int k,vector<vector<int>> d){
kako=d;
koliko=d;
for(int i=0;i<kako.size();i++)
for(int j=0;j<kako[i].size();j++)
kako[i][j]=0;
K=k;
N=d.size();
M=d[0].size();
for(int i=0;i<N;i++){
pok[i]=K-1;
for(int j=0;j<K;j++){
kako[i][j]=-1;
vred-=koliko[i][j];
}
stavi(i);
}
for(int it=1;it<=N*K/2;it++){
int gde=PQ.top().gde;
// cout<<gde<<" "<<pok[gde]<<endl;
vred+=PQ.top().dob;
PQ.pop();
kako[gde][pok[gde]]=0;
kako[gde][pok[gde]+M-K]=1;
pok[gde]--;
stavi(gde);
}
for(int i=0;i<N;i++){
niz[i]=i;
for(int j=0;j<M;j++){
if(kako[i][j]==0)
continue;
if(kako[i][j]==1)
p[niz[i]].push_back(j);
else
m[niz[i]].push_back(j);
}
}
for(int i=0;i<kako.size();i++)
for(int j=0;j<kako[i].size();j++)
kako[i][j]=-1;
for(int it=0;it<K;it++){
// cout<<it<<endl;
sort(niz,niz+N,cmp);
//for(int i=0;i<N;i++)
// cout<<niz[i].m.size()<<" "<<niz[i].p.size()<<endl;
for(int i=0;i<N/2;i++){
kako[niz[i]][m[niz[i]].back()]=it;
m[niz[i]].pop_back();
}
for(int i=N/2;i<N;i++){
kako[niz[i]][p[niz[i]].back()]=it;
p[niz[i]].pop_back();
}
}
allocate_tickets(kako);
return vred;
}
Compilation message
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<kako.size();i++)
| ~^~~~~~~~~~~~
tickets.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int j=0;j<kako[i].size();j++)
| ~^~~~~~~~~~~~~~~
tickets.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0;i<kako.size();i++)
| ~^~~~~~~~~~~~
tickets.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int j=0;j<kako[i].size();j++)
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
18 ms |
2784 KB |
Output is correct |
6 |
Correct |
453 ms |
60392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
30 ms |
3084 KB |
Output is correct |
6 |
Correct |
638 ms |
67424 KB |
Output is correct |
7 |
Correct |
667 ms |
70684 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
372 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
380 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
20 ms |
2880 KB |
Output is correct |
14 |
Correct |
22 ms |
2832 KB |
Output is correct |
15 |
Correct |
634 ms |
76788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
252 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
27 ms |
3464 KB |
Output is correct |
6 |
Correct |
5 ms |
852 KB |
Output is correct |
7 |
Correct |
6 ms |
1108 KB |
Output is correct |
8 |
Correct |
777 ms |
75272 KB |
Output is correct |
9 |
Correct |
790 ms |
91384 KB |
Output is correct |
10 |
Correct |
771 ms |
90564 KB |
Output is correct |
11 |
Correct |
763 ms |
97100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
19 ms |
2732 KB |
Output is correct |
14 |
Correct |
20 ms |
2816 KB |
Output is correct |
15 |
Correct |
22 ms |
3028 KB |
Output is correct |
16 |
Correct |
26 ms |
3464 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
22 ms |
3028 KB |
Output is correct |
21 |
Correct |
23 ms |
3028 KB |
Output is correct |
22 |
Correct |
23 ms |
3224 KB |
Output is correct |
23 |
Correct |
25 ms |
3136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
18 ms |
2784 KB |
Output is correct |
12 |
Correct |
453 ms |
60392 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
30 ms |
3084 KB |
Output is correct |
18 |
Correct |
638 ms |
67424 KB |
Output is correct |
19 |
Correct |
667 ms |
70684 KB |
Output is correct |
20 |
Correct |
5 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
372 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
380 KB |
Output is correct |
24 |
Correct |
7 ms |
1108 KB |
Output is correct |
25 |
Correct |
20 ms |
2880 KB |
Output is correct |
26 |
Correct |
22 ms |
2832 KB |
Output is correct |
27 |
Correct |
634 ms |
76788 KB |
Output is correct |
28 |
Correct |
1 ms |
252 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
27 ms |
3464 KB |
Output is correct |
33 |
Correct |
5 ms |
852 KB |
Output is correct |
34 |
Correct |
6 ms |
1108 KB |
Output is correct |
35 |
Correct |
777 ms |
75272 KB |
Output is correct |
36 |
Correct |
790 ms |
91384 KB |
Output is correct |
37 |
Correct |
771 ms |
90564 KB |
Output is correct |
38 |
Correct |
763 ms |
97100 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
2 ms |
468 KB |
Output is correct |
49 |
Correct |
3 ms |
596 KB |
Output is correct |
50 |
Correct |
2 ms |
596 KB |
Output is correct |
51 |
Correct |
19 ms |
2732 KB |
Output is correct |
52 |
Correct |
20 ms |
2816 KB |
Output is correct |
53 |
Correct |
22 ms |
3028 KB |
Output is correct |
54 |
Correct |
26 ms |
3464 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
2 ms |
596 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
22 ms |
3028 KB |
Output is correct |
59 |
Correct |
23 ms |
3028 KB |
Output is correct |
60 |
Correct |
23 ms |
3224 KB |
Output is correct |
61 |
Correct |
25 ms |
3136 KB |
Output is correct |
62 |
Correct |
54 ms |
9532 KB |
Output is correct |
63 |
Correct |
55 ms |
9556 KB |
Output is correct |
64 |
Correct |
73 ms |
10916 KB |
Output is correct |
65 |
Correct |
266 ms |
39756 KB |
Output is correct |
66 |
Correct |
324 ms |
42476 KB |
Output is correct |
67 |
Correct |
6 ms |
1292 KB |
Output is correct |
68 |
Correct |
5 ms |
980 KB |
Output is correct |
69 |
Correct |
479 ms |
82208 KB |
Output is correct |
70 |
Correct |
623 ms |
89036 KB |
Output is correct |
71 |
Correct |
776 ms |
96956 KB |
Output is correct |
72 |
Correct |
662 ms |
81104 KB |
Output is correct |
73 |
Correct |
742 ms |
93576 KB |
Output is correct |
74 |
Correct |
546 ms |
73968 KB |
Output is correct |
75 |
Correct |
621 ms |
86532 KB |
Output is correct |