Submission #302917

#TimeUsernameProblemLanguageResultExecution timeMemory
3029178e7카니발 티켓 (IOI20_tickets)C++14
Compilation error
0 ms0 KiB
#include "tickets.h"
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
ll ab(ll a) {
	return a > 0 ? a : -a;
}
long long find_maximum(int k, vector<vector<int> > x) {
	int n = x.size();
	int m = x[0].size();
	vector<int> a;
	for (int i = 0;i < n;i++) {
		a.push_back(x[i][0]);
	}
	sort(a.begin(), a.end());
	//cout << n << ' ' << m;
	int med = n % 2 ? a[n / 2][0] : (a[n / 2 - 1][0] + a[n / 2][0]) / 2;
	//cout << med << " " << endl;
	vector<vector<int> > answer;
	ll val = 0;
	for (int i = 0; i < n; i++) {
		vector<int> row(m);
		for (int j = 0; j < m; j++) {
			//cout << x[i][j] << " ";
			if (j < k) {
				row[j] = j;
				val += ab(med - x[i][j]);
			} else {
				row[j] = -1;
			}
		}
		answer.push_back(row);
	}
	med++;
	ll v2 = 0;
	for (int j = 0; j < n; j++) {
		v2 += ab(med - x[j][0]);
	}
	allocate_tickets(answer);
	return min(val, v2);
}
/*
6 1 1
1
2
3
5
9
10
 */

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:19:30: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   19 |  int med = n % 2 ? a[n / 2][0] : (a[n / 2 - 1][0] + a[n / 2][0]) / 2;
      |                              ^
tickets.cpp:19:49: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   19 |  int med = n % 2 ? a[n / 2][0] : (a[n / 2 - 1][0] + a[n / 2][0]) / 2;
      |                                                 ^
tickets.cpp:19:63: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   19 |  int med = n % 2 ? a[n / 2][0] : (a[n / 2 - 1][0] + a[n / 2][0]) / 2;
      |                                                               ^