이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
#define pb push_back
#define se second
#define fi first
long long find_maximum(int k, std::vector<std::vector<int>> x) {
long long n = x.size();
long long m = x[0].size();
vector<vector<long long>> y(n,vector<long long> (m));
vector<vector<int>> ans(n,vector<int> (m,-1));
priority_queue<pair<long long,int>> pq;
long long res=0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
y[i][j]=x[i][j];
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < k; ++j)
{
res-=y[i][j];
}
}
int l[n];
int r[n];
for (int i = 0; i < n; ++i)
{
l[i]=k-1;
r[i]=m-1;
pq.push({y[i][l[i]]+y[i][r[i]],i});
}
for (int i = 0; i < 1ll*k*n/2; ++i)
{
auto cur=pq.top();
res+=cur.fi;
pq.pop();
l[cur.se]--;
r[cur.se]--;
if(l[cur.se]==-1||r[cur.se]==m-k-1) continue;
pq.push({1ll*(y[cur.se][l[cur.se]]+y[cur.se][r[cur.se]]),cur.se});
}
while(!pq.empty()) pq.pop();
vector<pair<int,int>> a;
set<pair<int,int>> b;
for (int i = 0; i < n; ++i)
{
int cnt=0;
pq.push({l[i],i});
r[i]++;
}
for (int i = 0; i < k; ++i)
{
set<int> cnt;
for (int j = 0; j < n/2; ++j)
{
auto cur=pq.top();
cnt.insert(cur.se);
pq.pop();
ans[cur.se][cur.fi]=i;
}
for (int j = 0; j < n; ++j)
{
if(!cnt.count(j)){
ans[j][r[j]]=i;
r[j]++;
}
}
for(auto u:cnt){
l[u]--;
pq.push({l[u],u});
}
}
allocate_tickets(ans);
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:51:7: warning: unused variable 'cnt' [-Wunused-variable]
51 | int cnt=0;
| ^~~
# | 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... |