Submission #716180

# Submission time Handle Problem Language Result Execution time Memory
716180 2023-03-29T08:02:34 Z Baytoro Gondola (IOI14_gondola) C++17
100 / 100
58 ms 5972 KB
#include "gondola.h"
#include <bits/stdc++.h>
//#include "grader.cpp"

using namespace std;
int valid(int n, int a[]){
	map<int,int> mp;
	for(int i=0;i<n;i++){
		if(mp[a[i]]!=0) return 0;
		mp[a[i]]=1;
	}
	vector<pair<int,int>> v;
	for(int i=0;i<n;i++){
		if(a[i]<=n){
			v.push_back({a[i],i});
		}
	}
	sort(v.begin(),v.end());
	for(int i=1;i<(int)v.size();i++){
		int k=(v[i].first-v[i-1].first);
		int s=(v[i].second-v[i-1].second+n)%n;
		if(k!=s) return 0;
	}
	return 1;
}

//----------------------
bool cmp(pair<int,int> a, pair<int,int> b){
	return a.second<b.second;
}
int replacement(int n, int a[], int ans[]){
	for(int i=0;i<n;i++) a[i]--;
	bool ok=0;
	vector<pair<int,int>> v;
	for(int i=0;i<n;i++){
		if(a[i]<n){
			ok=1;
			for(int j=1;j<n;j++){
				if(a[(j+i)%n]>=n){
					v.push_back({(a[i]+j)%n,a[(i+j)%n]});
				}
			}
			break;
		}
	}
	if(!ok && v.empty()){
		for(int i=0;i<n;i++) 
			v.push_back({i,a[i]});
	}
	sort(v.begin(),v.end(),cmp);
	int cnt=0;
	for(auto it: v){
		int l=it.first,r=it.second;
		while(l!=r){
			ans[cnt]=l+1;
			l=n+cnt;
			cnt++;
		}
	}
	return cnt;
}
#define ll long long
//----------------------
const int mod=1e9+9;
ll binpow(ll a, ll b){
	if(b==0) return 1;
	if(b%2) return (binpow(a,b-1)*a)%mod;
	ll k=binpow(a,b/2);
	return (k*k)%mod;
}
int countReplacement(int n, int a[]){
	if(!valid(n,a)) return 0;
	ll ans=1,c=0;
	vector<int> v;
	for(int i=0;i<n;i++){
		if(a[i]>n) {v.push_back(a[i]);c++;}
	}
	if((int)v.size()==n) ans=n;
	sort(v.begin(),v.end());
	for(int i=0;i<(int)v.size();i++){
		int x;
		if(i==0) x=v[i]-n-1;
		else x=v[i]-v[i-1]-1;
		ans*=binpow(c--,x);
		ans%=mod; 
	}
	
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 16 ms 2848 KB Output is correct
7 Correct 8 ms 748 KB Output is correct
8 Correct 27 ms 5216 KB Output is correct
9 Correct 11 ms 1876 KB Output is correct
10 Correct 47 ms 5704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 15 ms 2896 KB Output is correct
7 Correct 8 ms 780 KB Output is correct
8 Correct 29 ms 5148 KB Output is correct
9 Correct 12 ms 1876 KB Output is correct
10 Correct 38 ms 5704 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 17 ms 2124 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 47 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 652 KB Output is correct
12 Correct 9 ms 724 KB Output is correct
13 Correct 13 ms 1304 KB Output is correct
14 Correct 8 ms 628 KB Output is correct
15 Correct 18 ms 2292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 39 ms 4812 KB Output is correct
10 Correct 33 ms 4148 KB Output is correct
11 Correct 11 ms 1524 KB Output is correct
12 Correct 20 ms 1856 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 220 KB Output is correct
5 Correct 1 ms 220 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 42 ms 4764 KB Output is correct
10 Correct 36 ms 4176 KB Output is correct
11 Correct 13 ms 1592 KB Output is correct
12 Correct 20 ms 1884 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 51 ms 5376 KB Output is correct
15 Correct 58 ms 5972 KB Output is correct
16 Correct 10 ms 1304 KB Output is correct
17 Correct 37 ms 4048 KB Output is correct
18 Correct 19 ms 2376 KB Output is correct