Submission #737651

# Submission time Handle Problem Language Result Execution time Memory
737651 2023-05-07T13:23:28 Z esomer Gondola (IOI14_gondola) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "gondola.h"
 
using namespace std;

const int MOD = 1e9 + 7;

//~ int inputSeq[1000];
//~ int gondolaSeq[1000];
//~ int replacementSeq[1000];

long long pw(int a, int b){
	if(b == 0) return 1;
	if(b % 2 == 0){
		long long x = pw(a, b/2);
		return (x * x) % MOD;
	}else{
		long long x = pw(a, b/2);
		x = (x * x) % MOD;
		return (x * a) % MOD;
	}
}
 
int valid(int n, int* inputSeq){
	map<int, int> cnt;
	int mn = 1e9;
	int ind;
	for(int i = 0; i < n; i++){
		if(mn > inputSeq[i]){
			mn = inputSeq[i];
			ind = i;
		}
		cnt[inputSeq[i]]++;
		if(cnt[inputSeq[i]] > 1) return 0; 
	}
	if(mn > n) return 1;
	int curr = mn + 1;
	for(int i = ind + 1; i % n != ind; i++){
		if(inputSeq[i % n] <= n && inputSeq[i % n] != curr) return 0;
      	curr++;
	}
	return 1;
}
 
int replacement(int n, int* gondolaSeq, int* replacementSeq){
	int ind = 0;
	int add = 1e9;
	vector<pair<int, int>> v;
	for(int i = 0; i < n; i++){
		if(gondolaSeq[i] <= n && gondolaSeq[i] < add){
			add = gondolaSeq[i];
			ind = i;
		}
		if(gondolaSeq[i] > n){
			v.push_back({gondolaSeq[i], i});
		}
	}
	if(add == 1e9) add = 1;
	sort(v.begin(), v.end());
	int nxt = n + 1;
	int curr = 0;
	for(auto p : v){
		int initial;
		if(p.second < ind) initial = n - ind + p.second + add;
		else initial = p.second - ind + add;
		initial %= n;
		if(initial == 0) initial = n;
		//~ cout << "p " << p.first << " " << p.second << " initial " << initial << " curr " << curr << " nxt " << nxt << " add " << add << endl;
		replacementSeq[curr] = initial; curr++;
		while(nxt != p.first){
			replacementSeq[curr] = nxt; nxt++; curr++;
		}
		nxt = p.first + 1;
	}
	return curr;
}
 
int countReplacement(int n, int* inputSeq){
	map<int, int> cnt;
	int mn = 1e9;
	int mx = 0;
	int ind;
	int broken = 0;
	vector<int> v;
	for(int i = 0; i < n; i++){
		if(mn > inputSeq[i]){
			mn = inputSeq[i];
			ind = i;
		}
		cnt[inputSeq[i]]++;
		if(cnt[inputSeq[i]] > 1) return 0; 
		mx = max(mx, inputSeq[i]); 
		if(inputSeq[i] > n) {broken++; v.push_back(inputSeq[i]);}
	}
	int curr = mn + 1;
	for(int i = ind + 1; i % n != ind; i++){
		if(inputSeq[i % n] <= n && inputSeq[i % n] != curr) return 0;
      	curr++;
	}
	long long ans = 1;
	int lst = n;
	sort(v.begin(), v.end());	
	for(int x : v){
		ans *= pw(broken, x - lst - 1); ans %= MOD;
		broken--; lst = x;
	}
	return (int)ans;
}

//~ int main(){
	//~ int t, n; cin >> t >> n;
	//~ if(t >= 4 && t <= 6){
		//~ for(int i = 0; i < n; i++) cin >> gondolaSeq[i];
		//~ cout << replacement(n) << endl;
		//~ for(int i = 0; i < 5*n; i++) cout << replacementSeq[i] << " ";
		//~ cout << endl;
	//~ }else{
		//~ for(int i = 0; i < n; i++) cin >> inputSeq[i];
		//~ cout << countReplacement(n) << endl;
	//~ }
}

Compilation message

gondola.cpp:121:1: error: expected declaration before '}' token
  121 | }
      | ^