이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF=1e18;
int n,m,k;
vector<vector<int> > arr;
vector<vector<int> > state;
vector<vector<int> > ans;
vector<int> white[1505];
vector<int> black[1505];
bool vis[1505];
int pos[1505];
priority_queue<ii> pq;
long long find_maximum(int _k, std::vector<std::vector<int>> _arr) {
n=sz(_arr),m=sz(_arr[0]),arr=_arr;
k=_k;
rep(x,0,n){
ans.push_back(vector<int>());
rep(y,0,m) ans[x].push_back(-1);
state.push_back(vector<int>());
rep(y,0,m) state[x].push_back(-1);
pos[x]=k-1;
pq.push(ii(arr[x][pos[x]+m-k]+arr[x][pos[x]],x));
}
int node;
rep(zzz,0,n*k/2){
node=pq.top().se,pq.pop();
state[node][pos[node]+m-k]=1;
pos[node]--;
if (pos[node]==-1) continue;
pq.push(ii(arr[node][pos[node]+m-k]+arr[node][pos[node]],node));
}
rep(x,0,n){
rep(y,0,pos[x]+1) state[x][y]=0;
}
ll res=0;
rep(x,0,n){
rep(y,0,m){
//cout<<state[x][y]<<" ";
if (state[x][y]==0){
res-=arr[x][y];
white[x].push_back(y);
}
else if (state[x][y]==1){
res+=arr[x][y];
black[x].push_back(y);
}
}
//cout<<endl;
}
rep(idx,0,k){
memset(vis,false,sizeof(vis));
int currw=0;
rep(x,0,n){
if (white[x].empty()){
vis[x]=true;
ans[x][black[x].back()]=idx;
black[x].pop_back();
}
else if (black[x].empty()){
vis[x]=true;
ans[x][white[x].back()]=idx;
white[x].pop_back();
currw++;
}
}
rep(x,0,n) if (!vis[x]){
if (currw==n/2){
ans[x][black[x].back()]=idx;
black[x].pop_back();
}
else {
ans[x][white[x].back()]=idx;
white[x].pop_back();
currw++;
}
}
}
allocate_tickets(ans);
return res;
}
# | 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... |