이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "tickets.h"
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define sz(a) (int)a.size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const ll inf=1e18;
const int mod=1e9+7;
const int maxn=2e3+5;
int n,m,num[maxn][3],cnt[3];
int us[maxn],t,an,taken;
ll ans;
vi b[maxn][3],d,v;
vector<vector<int>>s;
set <int>g[3];
void f(int tp,int round){
memset(us,0,sizeof(us));
t = 0;
d.clear();
for(auto i : g[tp]){
if(t==n/2) break;
us[i]=1;
b[i][tp].pb(round);
num[i][tp]--;
if(num[i][tp]==0) d.pb(i);
}
taken=0;
for(auto i : d) g[tp].erase(i);
d.clear();
if(tp==1) an=0;
else an=1;
for(auto i : g[an]){
if(us[i]) continue;
b[i][an].pb(round);
num[i][an]--;
if(num[i][an]==0) d.pb(i);
taken++;
}
for(auto i : d) g[an].erase(i);
ans += min(t,taken);
}
ll find_maximum(int k,vector<vector<int>>x){
n=sz(x);
m=sz(x[0]);
s.resize(n);
for(int i = 0;i < n;i++) s[i].resize(m);
if(m==1){
for(int i = 0;i < n;i++) v.pb(x[i][0]);
sort(v.begin(),v.end());
for(int i = 0;i < n;i++) ans += abs(v[n/2]-v[i]);
allocate_tickets(s);
return ans;
}
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++) num[i][x[i][j]]++;
if(num[i][0]) g[0].insert(i);
if(num[i][1]) g[1].insert(i);
cnt[0] += num[i][0];
cnt[1] += num[i][1];
}
for(int i = 0;i < k;i++){
if(cnt[0] < cnt[1]) f(0,i);
else f(1,i);
}
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
if(sz(b[i][x[i][j]])){
s[i][j]=b[i][x[i][j]].back();
b[i][x[i][j]].pop_back();
}
else s[i][j]=-1;
}
}
allocate_tickets(s);
return ans;
}
# | 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... |