이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define ln "\n"
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
#define all(a) a.begin(),a.end()
long long find_maximum(int k, std::vector<std::vector<int>> x) {
ll N = x.size();
ll M = x[0].size();
{
vector<std::tuple<ll,ll,ll>> data;
rep(i,0,N){
rep(j,0,M) data.pb(mtp(x[i][j],i,j));
}
sort(all(data));
ll ans = 0;
ll mid = N*M/2;
vii left(N), right(N);
rep(i,0,mid){
ll val, I,J; std::tie(val, I,J) = data[i];
left[I].pb(J);
}
rep(i,mid,N*M){
ll val, I,J; std::tie(val, I,J) = data[i];
right[I].pb(J);
}
vii use_left(N), use_right(N);
ll goal = N*k/2;
ll current = 0;
std::priority_queue<pii> que;
rep(i,0,N){
rep(j,left[i].size(),k){
use_right[i].pb(right[i].back());
right[i].pop_back();
current++;
}
while(left[i].size() > k) left[i].pop_back();
if(right[i].empty() || left[i].empty()) continue;
que.push(mp(right[i].back()+left[i].back(), i));
}
/*rep(i,0,N){
cout << "! " << i << ln;
for(auto el: left[i]) cout << el << " ";
cout << ln;
for(auto el: use_right[i]) cout << el << " ";
cout << ln;
}*/
while(current < goal){
auto el = que.top(); que.pop();
ll i = el.second;
left[i].pop_back();
use_right[i].pb(right[i].back());
right[i].pop_back();
current++;
if(right[i].empty() || left[i].empty()) continue;
que.push(mp(right[i].back()+left[i].back(), i));
}
use_left = left;
vector<vector<int>> allocate(N,vector<int>(M,-1));
vector<pii> cnt(k);
rep(i,0,M) cnt[i] = mp(0,i);
rep(i,0,N){
sort(all(cnt));
ll idx = 0;
for(auto el: use_left[i]){
allocate[i][el] = cnt[idx].second;
cnt[idx].first++;
idx++;
ans -= x[i][el];
}
for(auto el: use_right[i]){
allocate[i][el] = cnt[idx].second;
cnt[idx].first--;
idx++;
ans += x[i][el];
}
}
allocate_tickets(allocate);
return ans;
}
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:54:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
54 | while(left[i].size() > k) left[i].pop_back();
| ~~~~~~~~~~~~~~~^~~
# | 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... |