이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
//#define int long long
long long find_maximum(int k, vector<vector<int>> x) {
int n=x.size(),m=x[0].size();
if(k==1){
vector<vector<int>> ans(n,vector<int>(m,-1));
vector<pair<int,int>> v(n);
vector<int> a;
for(int i=0;i<n;i++){
v[i]={x[i][0]+x[i][m-1],i};
}
sort(v.begin(),v.end());
for(int i=0;i<n/2;i++){
ans[v[i].sc][0]=0;
a.pb(x[v[i].sc][0]);
}
for(int i=n/2;i<n;i++){
ans[v[i].sc][m-1]=0;
a.pb(x[v[i].sc][m-1]);
}
allocate_tickets(ans);
sort(a.begin(),a.end());
long long s=(a[n/2]),res=0;
for(int i=0;i<n;i++) res+=abs(s-a[i]);
return res;
}
else if(k==m){
vector<vector<int>> ans(n,vector<int>(m,-1));
int res=0;
vector<int> l(n),r(n,m-1),id(n),a(n);
iota(id.begin(),id.end(),0);
vector<pair<int,int>> v;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
v.pb({x[i][j],i});
}
sort(v.begin(),v.end());
for(int i=0;i<(int)v.size()/2;i++)
a[v[i].sc]++;
for(int t=0;t<k;t++){
sort(id.begin(),id.end(),[&](int i, int j){
return a[i]>a[j];
});
long long X=0,Y=0;
for(int i=0;i<n/2;i++){
X+=x[id[i]][l[id[i]]];
ans[id[i]][l[id[i]]]=t;
a[id[i]]--;
l[id[i]]++;
}
for(int i=n/2;i<n;i++){
Y+=x[id[i]][r[id[i]]];
ans[id[i]][r[id[i]]]=t;
r[id[i]]--;
}
res+=Y-X;
}
allocate_tickets(ans);
return res;
}
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
68 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |