## Submission #307754

# Submission time Handle Problem Language Result Execution time Memory
307754 2020-09-29T09:25:24 Z cheetose Carnival Tickets (IOI20_tickets) C++17
100 / 100
1167 ms 62500 KB
```#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
#include "tickets.h"
int n,m,kk;
/*void allocate_tickets(vector<Vi> &s){
int n=s.size(),m=s[0].size();
fup(i,0,n-1,1){
fup(j,0,m-1,1){
printf("%d ",s[i][j]);
}
puts("");
}
}*/
int cnt[1500];
Pi p[1500];
ll find_maximum(int k, vector<Vi> x){
kk=k,n=x.size(),m=x[0].size();
vector<Vi> s(n,Vi(m,-1));
ll res=0;
fup(i,0,n-1,1)fup(j,0,k-1,1)res-=x[i][j];
fup(i,0,n-1,1)p[i].Y=m,cnt[i]=k;
priority_queue<Pi> q;
fup(i,0,n-1,1){
fup(j,0,k-1,1)q.push(mp(x[i][j]+x[i][j+m-k],i));
}
fup(K,1,n*k/2,1){
Pi P=q.top();
q.pop();
res+=P.X;
p[P.Y].Y--;
cnt[P.Y]--;
}
fup(K,0,k-1,1){
VPi vv(n);
fup(i,0,n-1,1)vv[i]=mp(cnt[i],i);
sort(ALL(vv));
fup(i,0,n/2-1,1){
int ii=vv[i].Y;
s[ii][p[ii].Y++]=K;
}
fup(i,n/2,n-1,1){
int ii=vv[i].Y;
s[ii][p[ii].X++]=K;
cnt[ii]--;
}
}
allocate_tickets(s);
return res;
}/*
int main() {
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
vector<Vi> x(n,Vi(m));
fup(i,0,n-1,1)fup(j,0,m-1,1)scanf("%d",&x[i][j]);
printf("%lld\n",find_maximum(k,x));
}*/```

### Compilation message

```tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:58:2: note: in expansion of macro 'fup'
58 |  fup(i,0,n-1,1)fup(j,0,k-1,1)res-=x[i][j];
|  ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:58:16: note: in expansion of macro 'fup'
58 |  fup(i,0,n-1,1)fup(j,0,k-1,1)res-=x[i][j];
|                ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:59:2: note: in expansion of macro 'fup'
59 |  fup(i,0,n-1,1)p[i].Y=m,cnt[i]=k;
|  ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:61:2: note: in expansion of macro 'fup'
61 |  fup(i,0,n-1,1){
|  ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:62:3: note: in expansion of macro 'fup'
62 |   fup(j,0,k-1,1)q.push(mp(x[i][j]+x[i][j+m-k],i));
|   ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'K' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:64:2: note: in expansion of macro 'fup'
64 |  fup(K,1,n*k/2,1){
|  ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'K' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:71:2: note: in expansion of macro 'fup'
71 |  fup(K,0,k-1,1){
|  ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:73:3: note: in expansion of macro 'fup'
73 |   fup(i,0,n-1,1)vv[i]=mp(cnt[i],i);
|   ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:75:3: note: in expansion of macro 'fup'
75 |   fup(i,0,n/2-1,1){
|   ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
|                              ^
tickets.cpp:79:3: note: in expansion of macro 'fup'
79 |   fup(i,n/2,n-1,1){
|   ^~~```

#### Subtask #1 11.0 / 11.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 768 KB Output is correct

#### Subtask #2 16.0 / 16.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 30 ms 2432 KB Output is correct
6 Correct 726 ms 51464 KB Output is correct

#### Subtask #3 14.0 / 14.0

# 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 1 ms 256 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 28 ms 2456 KB Output is correct
6 Correct 732 ms 53528 KB Output is correct
7 Correct 794 ms 56524 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 8 ms 904 KB Output is correct
13 Correct 25 ms 2296 KB Output is correct
14 Correct 25 ms 2304 KB Output is correct
15 Correct 804 ms 58952 KB Output is correct

#### Subtask #4 14.0 / 14.0

# 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 1 ms 256 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 41 ms 2796 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 8 ms 1024 KB Output is correct
8 Correct 1113 ms 62372 KB Output is correct
9 Correct 1097 ms 58172 KB Output is correct
10 Correct 1086 ms 58264 KB Output is correct
11 Correct 1167 ms 62500 KB Output is correct

#### Subtask #5 12.0 / 12.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct

#### Subtask #6 23.0 / 23.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 30 ms 2424 KB Output is correct
14 Correct 31 ms 2424 KB Output is correct
15 Correct 36 ms 2584 KB Output is correct
16 Correct 41 ms 2796 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 33 ms 2684 KB Output is correct
21 Correct 37 ms 2552 KB Output is correct
22 Correct 35 ms 2672 KB Output is correct
23 Correct 39 ms 2676 KB Output is correct

#### Subtask #7 10.0 / 10.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 30 ms 2432 KB Output is correct
12 Correct 726 ms 51464 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 28 ms 2456 KB Output is correct
18 Correct 732 ms 53528 KB Output is correct
19 Correct 794 ms 56524 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 8 ms 904 KB Output is correct
25 Correct 25 ms 2296 KB Output is correct
26 Correct 25 ms 2304 KB Output is correct
27 Correct 804 ms 58952 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 41 ms 2796 KB Output is correct
33 Correct 7 ms 768 KB Output is correct
34 Correct 8 ms 1024 KB Output is correct
35 Correct 1113 ms 62372 KB Output is correct
36 Correct 1097 ms 58172 KB Output is correct
37 Correct 1086 ms 58264 KB Output is correct
38 Correct 1167 ms 62500 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 3 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 30 ms 2424 KB Output is correct
52 Correct 31 ms 2424 KB Output is correct
53 Correct 36 ms 2584 KB Output is correct
54 Correct 41 ms 2796 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 33 ms 2684 KB Output is correct
59 Correct 37 ms 2552 KB Output is correct
60 Correct 35 ms 2672 KB Output is correct
61 Correct 39 ms 2676 KB Output is correct
62 Correct 84 ms 6008 KB Output is correct
63 Correct 84 ms 6136 KB Output is correct
64 Correct 117 ms 7276 KB Output is correct
65 Correct 387 ms 24164 KB Output is correct
66 Correct 472 ms 28040 KB Output is correct
67 Correct 8 ms 1024 KB Output is correct
68 Correct 7 ms 768 KB Output is correct
69 Correct 711 ms 51576 KB Output is correct
70 Correct 897 ms 53452 KB Output is correct
71 Correct 1111 ms 62368 KB Output is correct
72 Correct 971 ms 59556 KB Output is correct
73 Correct 1091 ms 59120 KB Output is correct
74 Correct 773 ms 52552 KB Output is correct
75 Correct 904 ms 52284 KB Output is correct