#include "tickets.h"
#include <vector>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second
/*
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
for (int j = 0; j < m; j++) {
if (j < k) {
row[j] = j;
} else {
row[j] = -1;
}
}
answer.push_back(row);
}
allocate_tickets(answer);
return 1;
*/
const int mxn = 2022;
vector<vector<int>> ansv;
vector<int> choose[mxn];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int N = x.size();
int M = x[0].size();
int K = k;
ansv = vector<vector<int>>(N,vector<int>(M,-1));
{
vector<pair<int,pii>> v;
for(int i = 0;i<N;i++){
for(int j = 0;j<M;j++){
v.push_back(make_pair(x[i][j],pii(i,j)));
}
}
sort(v.rbegin(),v.rend());
for(int i = 0;i<N*M/2;i++){
int r = v[i].sc.fs,c = v[i].sc.sc;
choose[r].push_back(c);
}
}
ll ans = 0;
priority_queue<pii,vector<pii>,less<pii>> pq;
for(int i = 0;i<K;i++)pq.push(pii(N>>1,i));
for(int i = 0;i<N;i++){
vector<pii> v;
while(!pq.empty()&&v.size()<choose[i].size()){
v.push_back(pq.top());
pq.pop();
}
assert(v.size() == choose[i].size());
for(auto &j:choose[i]){
ansv[i][j] = v.back().sc;
if(v.back().fs > 1)pq.push(pii(v.back().fs-1,v.back().sc));
}
}
assert(pq.empty());
cerr<<"DEBUG: "<<endl;
for(int i = 0;i<N;i++){
for(int j =0;j<M;j++)cerr<<ansv[i][j]<<' ';cerr<<endl;
}cerr<<endl;
for(int i = 0;i<N;i++){
set<int> st;
for(int j = 0;j<M;j++)st.insert(j);
for(int j = 0;j<M;j++){
if(ansv[i][j] >= 0)st.erase(ansv[i][j]),ans += x[i][j];
else ans -= x[i][j];
}
for(int j = 0;j<M;j++){
if(ansv[i][j]>=00)continue;
ansv[i][j] = *st.begin();
st.erase(st.begin());
}
}
allocate_tickets(ansv);
return ans;
}
Compilation message
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:77:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
77 | for(int j =0;j<M;j++)cerr<<ansv[i][j]<<' ';cerr<<endl;
| ^~~
tickets.cpp:77:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
77 | for(int j =0;j<M;j++)cerr<<ansv[i][j]<<' ';cerr<<endl;
| ^~~~
# |
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 |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
8 |
Halted |
0 ms |
0 KB |
- |