이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <vector>
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
ll ans=0;
int n = x.size(),m = x[0].size();
vi big(n);
struct el {
int dif,color;
bool operator<(const el& o) {
return dif>o.dif;
}
};
vector<el> options;
for(int col=0;col<n;++col) {
auto& v = x[col];
for(int i=0;i<k;++i) ans-=v[i];
for(int i=0;i<k;++i) {
options.push_back({v[k-1-i]+v[m-1-i],col});
}
}
sort(all(options));
options.resize(n*k/2);
for(auto e : options) {
big[e.color]++;
ans+=e.dif;
}
vi small(n,m-1);
for(int i=0;i<n;++i) small[i]=k-big[i];
// construct it
for(auto& v : x) fill(all(v),-1);
for(int i=0;i<k;++i) {
vector<bool> vis(n);
int bal=0;
auto take=[&](int j) {
if(vis[j]) return;
vis[j]=true;
if(small[j]!=0 and (big[j]==0 or bal>0)) {
bal--;
x[j][--small[j]] = i;
} else {
x[j][m - big[j]--] = i;
bal++;
}
};
for(int j=0;j<n;++j) {
if(big[j]==0 or small[j]==0) {
take(j);
}
}
for(int j=0;j<n;++j) take(j);
}
allocate_tickets(x);
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... |