제출 #827562

#제출 시각아이디문제언어결과실행 시간메모리
827562minhcool카니발 티켓 (IOI20_tickets)C++17
100 / 100
801 ms61664 KiB
//#define local
#ifndef local
#include "tickets.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef pair<ii, ii> iiii;
 
const ll N = 3e5 + 5;
 
const ll oo = 1e18 + 7, mod = 1e9 + 7;
 
mt19937 rng(1);
 
ll rnd(ll l, ll r){
	ll temp = rng() % (r - l + 1);
	return abs(temp) + l;
}
 
ll n, m, itr[N];

int degbig[N], degsmall[N];

#ifdef local
void allocate_tickets(vector<vector<int>> vc){
    for(int i = 0; i < vc.size(); i++){
        for(int j = 0; j < vc[0].size(); j++) cout << vc[i][j] << " ";
        cout << "\n";
    }
}
#endif

bool cmp(ii a, ii b){
    if(a.fi != b.fi) return a.fi > b.fi;
    return a.se < b.se;
}
 
ll find_maximum(int k, vector<vector<int>> x){
    n = x.size(), m = x[0].size();
    ll sum = 0;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < k; j++) ans += (ll)x[i][m - j - 1];
        //cout << x[i][m - 1] << "\n";
        itr[i] = 0;
    }
    priority_queue<ii, vector<ii>> pq;
    //cout << ans << '\n';
    for(ll i = 0; i < n; i++) pq.push({-((ll)x[i][0] + x[i][m - k]), i});
    for(ll i = 1; i <= (n * k)/2; i++){
        ii temp = pq.top();
        pq.pop();
        itr[temp.se]++;
        //cout << temp.fi << "\n";
        ans += temp.fi;
        if(itr[temp.se] < k) pq.push({-((ll)x[temp.se][itr[temp.se]] + x[temp.se][m - k + itr[temp.se]]), temp.se});
    }
    vector<vector<int>> assign;
    assign.resize(n);
    for(int i = 0; i < k; i++) degbig[i] = degsmall[i] = n/2;
    for(ll i = 0; i < n; i++){
        assign[i].resize(m);
        for(int j = 0; j < m; j++) assign[i][j] = -1;
        vector<ii> v;
        for(int j = 0; j < k; j++) v.pb({degsmall[j], j});
        sort(v.begin(), v.end(), greater<ii>());
        for(int j = 0; j < itr[i]; j++){
            assign[i][j] = v[j].se;
            degsmall[v[j].se]--;
        }
        v.clear();
        for(int j = 0; j < k; j++) v.pb({degbig[j], j});
        sort(v.begin(), v.end(), cmp);
        for(int j = itr[i]; j < k; j++){
            //cout << v[j].fi << " " << v[j].se << "\n";
            assign[i][m - k + j] = v[j - itr[i]].se;
            degbig[v[j - itr[i]].se]--;
        }
    }
    allocate_tickets(assign);
    return ans;
}
 
#ifdef local
void process(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> temp;
    temp.resize(n);
    for(int i = 0; i < n; i++) temp[i].resize(m);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cin >> temp[i][j];
    }
    cout << find_maximum(k, temp);
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}
#endif

컴파일 시 표준 에러 (stderr) 메시지

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:51:8: warning: unused variable 'sum' [-Wunused-variable]
   51 |     ll sum = 0;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...