제출 #639223

#제출 시각아이디문제언어결과실행 시간메모리
639223slime카니발 티켓 (IOI20_tickets)C++14
11 / 100
2 ms696 KiB
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row(m);
		for (int j = 0; j < m; j++) {
			row[j] = -1;
		}
		answer.push_back(row);
	}

  priority_queue<pair<int, pair<int, int > > > pq;
  long long ans = 0;
  int chosen[n];

  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      pq.push({x[i][j], {i, j}});
    }
  }

  
  for(int i=0; i<n; i++) chosen[i] = 0;

  int cnt = 0;
  while(pq.size()) {
    if(chosen[pq.top().second.first] == k) {
      pq.pop(); continue;
    }
    chosen[pq.top().second.first]++;
    answer[pq.top().second.first][pq.top().second.second] = 1; // 1: add, -2: subtract, -1: not chosen
    ans += pq.top().first;
    pq.pop();
    cnt++;
    if(cnt == n*k / 2) break;
  }

  while(pq.size()) pq.pop();

  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      pq.push({-x[i][j], {i, j}});
    }
  }
  cnt = 0;

  while(pq.size()) {
    if(chosen[pq.top().second.first] == k) {
      pq.pop(); continue;
    }
    chosen[pq.top().second.first]++;
    answer[pq.top().second.first][pq.top().second.second] = -2; // 1: add, -2: subtract, -1: not chosen
    ans += pq.top().first;
    pq.pop();
    cnt++;
    if(cnt == n*k / 2) break;
  }
  
  while(pq.size()) pq.pop();
  
  int nxt = 0;

  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      if(answer[i][j] == 1) {

        answer[i][j] = nxt;
        nxt = (nxt + 1) % k;
      }
    }
  }

  for(int i=0; i<n; i++) {

    bool bruh[m];
    for(int j=0; j<m; j++) bruh[j] = 0;
    for(int j=0; j<m; j++) if(answer[i][j] >= 0) bruh[answer[i][j]] = 1;

    nxt = 0;

    for(int j=0; j<m; j++) {
      if(answer[i][j] == -2) {
        while(bruh[nxt]) nxt++;
        bruh[nxt] = 1;
        answer[i][j] = nxt;
      }
    }
  }
  

  allocate_tickets(answer);
  return ans;
  
}
#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...