제출 #401221

#제출 시각아이디문제언어결과실행 시간메모리
401221my99n카니발 티켓 (IOI20_tickets)C++14
11 / 100
2 ms716 KiB
#include "tickets.h"
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;

vector<vector<int>> answer;

long long findanswer (vector<tuple<int,int,int>> round) {
  sort(all(round));
  long long med = get<0>(round[round.size()/2]);
  long long ans = 0;
  for (int i = 0; i < round.size(); i++) {
    ans += abs(med-get<0>(round[i]));
  }
  return ans;
}

int roundcnt = 0;
void setanswer (vector<tuple<int,int,int>> round) {
  for (auto x : round) {
    int i = get<1>(x);
    int j = get<2>(x);
    answer[i][j] = roundcnt;
  }
  roundcnt++;
}

int used[2020];
long long find_maximum(int k, vector<vector<int>> x) {
	int n = x.size();
	int m = x[0].size();

  answer = vector<vector<int>>(n);
	for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      answer[i].push_back(-1);
    }
  }
  
  vector<tuple<int,int,int>> mn, mx;

  for (int i = 0; i < n; i++) {
    vector<pair<int,int>> temp;
    for (int j = 0; j < m; j++) {
      temp.push_back({x[i][j], j});
    }
    sort(all(temp));
    mn.push_back({temp[0].first, i, temp[0].second});
    mx.push_back({temp.back().first, i, temp.back().second});
  }
  sort(all(mn)); sort(all(mx));
  vector<tuple<int,int,int>> round1, round2;


  for (int i = 0; i <= n/2-1; i++) { // 0-3 when n == 8
    used[get<1>(mn[i])] = 1; round1.push_back(mn[i]);
  }
  int cnt = 0;
  for (int i = n-1; i >= 0; i--) {
    if (used[get<1>(mx[i])]) continue;
    cnt++;
    round1.push_back(mx[i]);
    if (cnt == n/2) break;
  }

  memset(used, 0, sizeof used);
  for (int i = n-1; i >= 0; i--) {
    used[get<1>(mx[i])] = 1; round2.push_back(mx[i]);
  }
  cnt = 0;
  for (int i = 0; i < n; i++) {
    if (used[get<1>(mn[i])]) continue;
    cnt++;
    round1.push_back(mn[i]);
    if (cnt == n/2) break;
  }

  long long ans = 0;
  if (findanswer(round1) > findanswer(round2)) {
    setanswer(round1);
  } else setanswer(round2);

  ans = max(findanswer(round1), findanswer(round2));

  allocate_tickets(answer);
	return ans;
}

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

tickets.cpp: In function 'long long int findanswer(std::vector<std::tuple<int, int, int> >)':
tickets.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for (int i = 0; i < round.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
#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...