이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
#include "tickets.h"
#include <vector>
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
int n,m;
vector<vector<pii>> s;
ll ans;
struct dt {
int a,b;
pii i,j;
pii idx;
};
struct cmp {
bool operator()(const dt &l,const dt &r) {
return (l.a+l.b)>(r.a+r.b);
}
};
long long find_maximum(int k, vector<vector<int>> x) {
n=x.size(); m=x[0].size(); //debug(n,m);
s.resize(n,vector<pii>(m,make_pair(-1,-1)));
priority_queue<dt,vector<dt>,cmp> pq;
for(int i=0;i<n;i++) {
for(int j=m-1;j>=m-k;j--) {
ans+=x[i][j];
s[i][j]={m-j-1,1};
dt temp;
temp.i={i,j}; temp.j={i,k-(m-1-j)-1};
temp.a=x[i][j]; temp.b=x[i][k-(m-1-j)-1];
temp.idx=s[i][j];
pq.push(temp);
}
}
int cntt=(k*n)/2; vector<tuple<int,int,int,int>> ar;
while(cntt--) {
dt cur=pq.top(); pq.pop();
ans-=(cur.a+cur.b);
pii I=cur.i,J=cur.j;
s[J.first][J.second]={cur.idx.first,0};
s[I.first][I.second]={-1,-1};
}
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
if(s[i][j].second!=-1) {
ar.push_back(tie(x[i][j],i,j,s[i][j].second));
}
}
}
vector<vector<int>> s2(n,vector<int>(m,-1));
vector<int> cnt(k,0);
set<int> unused[n];
for(int i=0;i<n;i++) {
for(int j=0;j<k;j++) unused[i].insert(j);
}
int last=0;
for(auto e:ar) {
int val,i,j,type;
tie(val,i,j,type)=e;
//s2[i][j]=cnt1[i]++;
if(!type) continue;
int select;
for(auto e2:unused[i]) {
if(cnt[e2]<n/2) {
select=e2; break;
}
}
cnt[select]++; s2[i][j]=select;
unused[i].erase(select);
}
for(auto e:ar) {
int val,i,j,type;
tie(val,i,j,type)=e;
if(type) continue;
int select;
for(auto e2:unused[i]) {
if(cnt[e2]<n) {
select=e2; break;
}
}
cnt[select]++; s2[i][j]=select;
unused[i].erase(select);
}
allocate_tickets(s2);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:83:9: warning: unused variable 'last' [-Wunused-variable]
83 | int last=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... |