제출 #771719

#제출 시각아이디문제언어결과실행 시간메모리
771719ono_de206카니발 티켓 (IOI20_tickets)C++14
컴파일 에러
0 ms0 KiB
#include "tickets.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long

typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int n, m;
vector<vector<int>> answer, a;
long long ret;

void solve1() {
	vector<int> l(n), r(n);
	for(int i = 0; i < n; i++) {
		l[i] = 0;
		r[i] = m - 1;
	}
	for(int t = 0; t < k; t++) {
		vector<int> v(n, 0);
		priority_queue<pair<int, int>> q1, q2;
		for(int i = 0; i < n; i++) {
			ret -= a[i][l[i]];
			q1.push({a[i][l[i]] + a[i][r[i]], i});
		}
		while(1) {
			if(q1.size() > q2.size()) {
				auto i = q1.top(); q1.pop();
				ret += i.ff;
				v[i.ss] ^= 1;
				q2.push({-i.ff, i.ss});
			} else {
				auto i1 = q1.top();
				auto i2 = q2.top();
				q1.pop(); q2.pop();
				if(i1.ff + i2.ff <= 0) break;
				v[i1.ss] ^= 1; v[i2.ss] ^= 1;
				ret += i1.ff + i2.ff;
				i1.ff *= -1; i2.ff *= -1;
				q1.push(i2);
				q2.push(i1);
			}
		}
		for(int i = 0; i < n; i++) {
			if(v[i] == 0) {
				answer[i][l[i]++] = t;
			} else {
				answer[i][r[i]--] = t;
			}
		}
	}
}

void solve2() {
	vector<int> l(n), r(n);
	vector<pair<int, int>> v;
	for(int i = 0; i < n; i++) {
		r[i] = m;
		for(int j = 0; j < m; j++) {
			v.eb(a[i][j], i);
		}
	}
	sort(all(v));
	for(int i = 0; i < n * m / 2; i++) {
		ret += v[i + n * m / 2].ff - v[i].ff;
		l[v[i].ss]++;
	}
	for(int t = 0; t < m; t++) {
		v.clear();
		for(int i = 0; i < n; i++) {
			v.eb(l[i], i);
		}
		sort(all(v));
		for(int i = n - 1; i >= n / 2; i--) {
			answer[v[i].ss][--l[v[i].ss]] = t;
		}
		for(int i = 0; i < n / 2; i++) {
			answer[v[i].ss][--r[v[i].ss]] = t;
		}
	}
}

void solve3() {
	vector<int> l(n), r(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			l[i] += (a[i][j] == 0);
		}
		r[i] = l[i];
	}
	long long ret = 0;
	for(int t = 0; t < k; t++) {
		vector<int> v(n);
		iota(all(v), 0);
		sort(all(v), [&](int x, int y) {
			return l[x] > l[y];
		});
		int pos = n;
		for(int j = 0; j < n; j++) {
			int i = v[j];
			if(l[i] == 0) {
				pos = j;
				break;
			}
			if(j >= n / 2 && r[i] < m) {
				pos = j;
				break;
			}
		}
		ret += min(pos, n - pos);
		for(int i = 0; i < pos; i++) {
			int id = v[i];
			answer[id][--l[id]] = t;
		}
		for(int i = pos; i < n; i++) {
			int id = v[i];
			answer[id][r[id]++] = t;
		}
	}
}


long long find_maximum(int k, vector<vector<int>> LOL) {
	a = LOL;
	n = a.size(); m = a[0].size();
	answer = vector<int>(n, vector<int>(m, -1));
	allocate_tickets(answer);
	if(m == 1) {
		solve1();
	} else if(k == m) {
		solve2();
	} else {
		solve3();
	}
	allocate_tickets(answer);
	return ret;
}

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

tickets.cpp: In function 'void solve1()':
tickets.cpp:31:21: error: 'k' was not declared in this scope
   31 |  for(int t = 0; t < k; t++) {
      |                     ^
tickets.cpp: In function 'void solve3()':
tickets.cpp:104:21: error: 'k' was not declared in this scope
  104 |  for(int t = 0; t < k; t++) {
      |                     ^
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:138:44: error: no matching function for call to 'std::vector<int>::vector(int&, std::vector<int>)'
  138 |  answer = vector<int>(n, vector<int>(m, -1));
      |                                            ^
In file included from /usr/include/c++/10/vector:67,
                 from tickets.h:1,
                 from tickets.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:653:2: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]'
  653 |  vector(_InputIterator __first, _InputIterator __last,
      |  ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:653:2: note:   template argument deduction/substitution failed:
tickets.cpp:138:44: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<int>')
  138 |  answer = vector<int>(n, vector<int>(m, -1));
      |                                            ^
In file included from /usr/include/c++/10/vector:67,
                 from tickets.h:1,
                 from tickets.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:625:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  625 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:625:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  625 |       vector(initializer_list<value_type> __l,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:607:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  607 |       vector(vector&& __rv, const allocator_type& __m)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:607:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  607 |       vector(vector&& __rv, const allocator_type& __m)
      |              ~~~~~~~~~^~~~
/usr/include/c++/10/bits/stl_vector.h:589:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>; std::false_type = std::integral_constant<bool, false>]'
  589 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:589:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/10/bits/stl_vector.h:585:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>; std::true_type = std::integral_constant<bool, true>]'
  585 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:585:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/10/bits/stl_vector.h:575:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  575 |       vector(const vector& __x, const allocator_type& __a)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:575:28: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  575 |       vector(const vector& __x, const allocator_type& __a)
      |              ~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:572:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  572 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:572:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:553:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  553 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:553:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:522:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  522 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:522:47: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const value_type&' {aka 'const int&'}
  522 |       vector(size_type __n, const value_type& __value,
      |                             ~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/10/bits/stl_vector.h:510:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  510 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:510:51: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const allocator_type&' {aka 'const std::allocator<int>&'}
  510 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |                             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:497:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  497 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:497:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:487:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]'
  487 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:487:7: note:   candidate expects 0 arguments, 2 provided