Submission #232106

# Submission time Handle Problem Language Result Execution time Memory
232106 2020-05-16T04:04:34 Z spdskatr Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 KB
#include "gondola.h"
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#define fi first
#define se second
#define MOD 1000000009

using namespace std;
typedef pair<int, int> pii;

int valid(int n, int inputSeq[]) {
	int offset = -1;
	for (int i = 0; i < n; i++) {
		if (inputSeq[i] <= n) {
			offset = (i - inputSeq[i] + 1 + n) % n;
			break;
		}
	}
	set<int> seen;
	if (offset == -1) {
		for (int i = 0; i < n; i++) {
			if (seen.find(inputSeq[i]) != seen.end()) return 0;
			seen.insert(inputSeq[i]);
		}
		return 1;
	} else {
		for (int i = 0; i < n; i++) {
			int ind = (offset+i) % n;
			if (inputSeq[ind] <= n) {
				if (inputSeq[ind] != i+1) return 0;
			} else {
				if (seen.find(inputSeq[ind] != seen.end()) return 0;
				seen.insert(inputSeq[ind]);
			}
		}
	}
	return 1;
}

//----------------------
namespace T2 {
	int original[100005], cnt;
	vector<pii> elems;

	int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
		int offset = -1;
		for (int i = 0; i < n; i++) {
			if (gondolaSeq[i] <= n) {
				offset = (i - gondolaSeq[i] + 1 + n) % n;
				break;
			}
		}
		if (offset == -1) {
			for (int i = 0; i < n; i++) original[i] = i+1;
		} else {
			for (int i = 0; i < n; i++) {
				original[(offset+i)%n] = i+1;
			}
		}
		for (int i = 0; i < n; i++) {
			if (gondolaSeq[i] > n) {
				elems.push_back({ gondolaSeq[i], i });
			}
		}
		sort(elems.begin(), elems.end());
		int cur = n+1;
		for (int i = 0; i < elems.size(); i++) {
			while (elems[i].fi >= cur) {
				replacementSeq[cnt++] = original[elems[i].se];
				original[elems[i].se] = cur++;
			}
		}
		return cnt;
	}
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	return T2::replacement(n, gondolaSeq, replacementSeq);
}

//----------------------

namespace T3 {
	typedef long long ll;
	vector<pii> elems;
	
	ll ex(ll n, ll p) {
		ll res = 1, cur = n;
		for (int b = 0; p > 0; b++) {
			if ((p >> b) & 1) {
				res = (res * cur) % MOD;
				p ^= (1 << b);
			}
			cur = (cur * cur) % MOD;
		}
		return res;
	}
	int countReplacement(int n, int inputSeq[]) {
		int offset = -1;
		ll ans = 1;
		for (int i = 0; i < n; i++) {
			if (inputSeq[i] <= n) {
				offset = (i - inputSeq[i] + 1 + n) % n;
				break;
			}
		}
		if (offset == -1) {
			ans *= n;
		} else {
			for (int i = 0; i < n; i++) {
				int ind = (offset+i) % n;
				if (inputSeq[ind] < n && inputSeq[ind] != i+1) return 0;
			}
		}
		for (int i = 0; i < n; i++) {
			if (inputSeq[i] > n) {
				elems.push_back({ inputSeq[i], i });
			}
		}
		sort(elems.begin(), elems.end());
		int cur = n+1;
		for (int i = 0; i < elems.size(); i++) {
			if (elems[i].fi < cur) return 0;
			ll p = (elems[i].fi - cur);
			ans = (ans * (ex(elems.size() - i, p) % MOD)) % MOD;
			cur = elems[i].fi + 1;
		}
		return (int)ans;
	}
}

int countReplacement(int n, int inputSeq[])
{
	return T3::countReplacement(n, inputSeq);
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:36:9: warning: init-statement in selection statements only available with -std=c++1z or -std=gnu++1z
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
         ^~~~
gondola.cpp:36:33: error: no match for 'operator!=' (operand types are 'int' and 'std::set<int>::iterator {aka std::_Rb_tree_const_iterator<int>}')
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/7/utility:70:0,
                 from /usr/include/c++/7/algorithm:60,
                 from gondola.cpp:4:
/usr/include/c++/7/bits/stl_pair.h:456:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:456:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from gondola.cpp:4:
/usr/include/c++/7/bits/stl_iterator.h:311:5: note: candidate: template<class _Iterator> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
     operator!=(const reverse_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:311:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from gondola.cpp:4:
/usr/include/c++/7/bits/stl_iterator.h:349:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
     operator!=(const reverse_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:349:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from gondola.cpp:4:
/usr/include/c++/7/bits/stl_iterator.h:1130:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
     operator!=(const move_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1130:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from gondola.cpp:4:
/usr/include/c++/7/bits/stl_iterator.h:1136:5: note: candidate: template<class _Iterator> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
     operator!=(const move_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1136:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/vector:61:0,
                 from gondola.cpp:5:
/usr/include/c++/7/bits/allocator.h:158:5: note: candidate: template<class _T1, class _T2> bool std::operator!=(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
     operator!=(const allocator<_T1>&, const allocator<_T2>&)
     ^~~~~~~~
/usr/include/c++/7/bits/allocator.h:158:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::allocator<_Tp>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/vector:61:0,
                 from gondola.cpp:5:
/usr/include/c++/7/bits/allocator.h:164:5: note: candidate: template<class _Tp> bool std::operator!=(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
     operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
     ^~~~~~~~
/usr/include/c++/7/bits/allocator.h:164:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::allocator<_Tp>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/vector:64:0,
                 from gondola.cpp:5:
/usr/include/c++/7/bits/stl_vector.h:1620:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator!=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
     operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
     ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:1620:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::vector<_Tp, _Alloc>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/set:60:0,
                 from gondola.cpp:7:
/usr/include/c++/7/bits/stl_tree.h:412:5: note: candidate: template<class _Val> bool std::operator!=(const std::_Rb_tree_iterator<_Tp>&, const std::_Rb_tree_const_iterator<_Val>&)
     operator!=(const _Rb_tree_iterator<_Val>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_tree.h:412:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::_Rb_tree_iterator<_Tp>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/set:60:0,
                 from gondola.cpp:7:
/usr/include/c++/7/bits/stl_tree.h:1553:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator!=(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
     operator!=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_tree.h:1553:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/set:61:0,
                 from gondola.cpp:7:
/usr/include/c++/7/bits/stl_set.h:937:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator!=(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)
     operator!=(const set<_Key, _Compare, _Alloc>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_set.h:937:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::set<_Key, _Compare, _Alloc>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
In file included from /usr/include/c++/7/set:62:0,
                 from gondola.cpp:7:
/usr/include/c++/7/bits/stl_multiset.h:920:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator!=(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)
     operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_multiset.h:920:5: note:   template argument deduction/substitution failed:
gondola.cpp:36:45: note:   mismatched types 'const std::multiset<_Key, _Compare, _Alloc>' and 'int'
     if (seen.find(inputSeq[ind] != seen.end()) return 0;
                                             ^
gondola.cpp:37:31: error: expected ')' before ';' token
     seen.insert(inputSeq[ind]);
                               ^
gondola.cpp:37:16: error: could not convert 'seen.std::set<int>::insert((*(const value_type*)(inputSeq + ((sizetype)(((long unsigned int)ind) * 4)))))' from 'std::pair<std::_Rb_tree_const_iterator<int>, bool>' to 'bool'
     seen.insert(inputSeq[ind]);
     ~~~~~~~~~~~^~~~~~~~~~~~~~~
gondola.cpp: In function 'int T2::replacement(int, int*, int*)':
gondola.cpp:71:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < elems.size(); i++) {
                   ~~^~~~~~~~~~~~~~
gondola.cpp: In function 'int T3::countReplacement(int, int*)':
gondola.cpp:126:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < elems.size(); i++) {
                   ~~^~~~~~~~~~~~~~