이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef LOCAL
#include "tickets.h"
#endif
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define pb push_back
#define se second
#define fi first
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b-1); i >= (a); --i)
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const ll INF=1e18;
const int MX=1500+10;
//------------------------------------------------------------//
int N,M,K;
void allocate(vector<vi>ans){
#ifndef LOCAL
allocate_tickets(ans);
return;
#endif
FOR(i,0,N) FOR(j,0,M) cout << ans[i][j] << " \n"[j==M-1];
}
ll find_maximum(int K, vector<vi> X) {
N = X.size();
M = X[0].size();
::K=K;
int z=0;
FOR(i,0,N) FOR(j,0,K) z+=(!X[i][j]);
ckmin(z,(N*K)/2);
int r=(N*K)/2-z;
vector<vi>ans;
ans.resize(N);
FOR(i,0,N){
ans[i].assign(M,-1);
}
ll val=0;
int k=0;
FOR(i,0,N){
set<int>s;
FOR(j,0,K) s.insert(j);
int mn=0;
FOR(j,0,K){
if(!X[i][j]){
if(!z) break;
ans[i][j]=k;
s.erase(k);
mn++;
val-=X[i][j];
z--;
k++; k%=K;
}
else if(r){
ans[i][j]=k;
s.erase(k);
mn++;
val-=X[i][j];
r--;
k++; k%=K;
}
}
int mn2=K-mn;
FOR(j,M-mn2,M){
auto it=s.begin();
ans[i][j]=*it;
s.erase(it);
val+=X[i][j];
}
}
allocate(ans);
return val;
}
//-------------------------------------------------------------//
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
#ifdef LOCAL
int main(){
IO();
int N,M,K; cin>>N>>M>>K;
vector<vi>a;
a.resize(N);
FOR(i,0,N){
a[i].resize(M);
FOR(j,0,M) cin>>a[i][j];
}
cout << find_maximum(K,a) << endl;
}
#endif
/*
4 2 1
5 9
1 4
3 6
2 7
*/
# | 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... |