Submission #769021

# Submission time Handle Problem Language Result Execution time Memory
769021 2023-06-29T05:14:52 Z ono_de206 Comparing Plants (IOI20_plants) C++14
Compilation error
0 ms 0 KB
#include "plants.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;

vector<int> a;
set<int> s;
int n, k;

bool check(int i) {
	if(s.size() == 1) return 1;
	s.erase(i);
	auto l = s.lower_bound(i);
	if(l == s.end()) l = s.begin();
	if(abs((*l) - i) < k) {
		s.in(i);
		return 0;
	}
	l = s.lower_bound(i);
	if(l == s.begin()) l = s.rbegin();
	l--;
	if(abs((*l) - i) < k) {
		s.in(i);
		return 0;
	}
	s.in(i);
	return 1;
}

void init(int _k, vector<int> r) {
	k = _k;
	n = r.size();
	a.resize(n);
	for(int i = 0; i < n; i++) {
		if(r[i] == 0) s.in(i);
	}
	int now;
	for(int i = 0; i < n; i++) {
		if(check(i)) now = i;
	}
	for(int i = n; i >= 1; i--) {
		a[now] = i;
		s.erase(now);
		for(int j = 1; j < k; j++) {
			int id = (i - j + n) % n;
			r[id]--;
			if(r[id] == 0) s.in(id);
		}
		for(int j = 1; j < k; j++) {
			int id = (i - j + n) % n;
			if(r[id] == 0 && check(id)) {
				now = id;
				break;
			}
			id = (i + j) % n;
			if(r[id] == 0 && check(id)) {
				now = id;
				break;
			}
		}
	}
}

int compare_plants(int x, int y) {
	if(a[x] > a[y]) return 1;
	else return -1;
	return 0;
}

Compilation message

plants.cpp: In function 'bool check(int)':
plants.cpp:35:34: error: no match for 'operator=' (operand types are 'std::_Rb_tree_const_iterator<int>' and 'std::set<int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<int> >'})
   35 |  if(l == s.begin()) l = s.rbegin();
      |                                  ^
In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from plants.cpp:2:
/usr/include/c++/10/bits/stl_tree.h:328:12: note: candidate: 'constexpr std::_Rb_tree_const_iterator<int>& std::_Rb_tree_const_iterator<int>::operator=(const std::_Rb_tree_const_iterator<int>&)'
  328 |     struct _Rb_tree_const_iterator
      |            ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_tree.h:328:12: note:   no known conversion for argument 1 from 'std::set<int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<int> >'} to 'const std::_Rb_tree_const_iterator<int>&'
/usr/include/c++/10/bits/stl_tree.h:328:12: note: candidate: 'constexpr std::_Rb_tree_const_iterator<int>& std::_Rb_tree_const_iterator<int>::operator=(std::_Rb_tree_const_iterator<int>&&)'
/usr/include/c++/10/bits/stl_tree.h:328:12: note:   no known conversion for argument 1 from 'std::set<int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<int> >'} to 'std::_Rb_tree_const_iterator<int>&&'