답안 #200801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200801 2020-02-08T07:34:48 Z mohammad 곤돌라 (IOI14_gondola) C++14
100 / 100
81 ms 6136 KB
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒mohammad▒▀██████▄
░███▀▒▒▒▒alaa▒▒▒▒▒▒▀█████
░▐██▒▒▒alwrawrah▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
 
#include<bits/stdc++.h>
#include "gondola.h"
using namespace std;
 
typedef long long ll ;
const ll oo = 4294967296 ;
const double PI = acos(-1) ;
const ll M = 1e9 + 9   ;

map<int,int> mp;
vector<pair<int,int>> v;
pair<int, int> p[1000010] ;

int valid(int n, int inputSeq[]){
	bool b = false ;
	for(int i = 0 ; i < n ; ++i){
		mp[inputSeq[i]]++;
		if(mp[inputSeq[i]] > 1)return 0;
		if(inputSeq[i] <= n){
			b = 1 ;
			int x = inputSeq[i];
			int f = i - 1;
			while(f > -1 && inputSeq[f] > n){
				x--;
				if(x == 0) x = n;
				inputSeq[f] = x;
				mp[x]++;
				if(mp[x] > 1) return 0 ;
				f--;
			}
			f = i + 1 ;
			x = inputSeq[i];
			while(f < n && inputSeq[f] > n){
				x++;
				if(x == n + 1) x = 1;
				inputSeq[f] = x;
				mp[x]++;
				if(mp[x] > 1)return 0;
				f++;
			}
		}
	}
	if(b){
		for(int i = 1 ; i < n ; ++i)
			if((inputSeq[i] == 1 && inputSeq[i - 1] != n) || (inputSeq[i] != 1 && inputSeq[i - 1] + 1 != inputSeq[i])) return 0;
	}
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	bool b = false ;
	for(int i = 0 ; i < n ; ++i){
		p[i] = {gondolaSeq[i] , i + 1};
		mp[gondolaSeq[i]]++;
		if(mp[gondolaSeq[i]] > 1)return 0;
		if(gondolaSeq[i] <= n){
			b = 1;
			int x = gondolaSeq[i];
			int f = i - 1;
			while(f > -1 && gondolaSeq[f] > n){
				x--;
				if(x == 0) x = n;
				v.push_back({gondolaSeq[f] , x});
				gondolaSeq[f] = x;
				mp[x]++;	
				if(mp[x] > 1) return 0 ;
				f--;
			}
			f = i + 1 ;
			x = gondolaSeq[i];
			while(f < n && gondolaSeq[f] > n){
				x++;
				if(x == n + 1) x = 1;
				v.push_back({gondolaSeq[f] , x});
				gondolaSeq[f] = x;
				mp[x]++;
				if(mp[x] > 1)return 0;
				f++;
			}
			i = f - 1;
		}
	}
	int l = 0 , ls = n + 1;
	if(b){
		for(int i = 1 ; i < n ; ++i)
			if((gondolaSeq[i] == 1 && gondolaSeq[i - 1] != n) || (gondolaSeq[i] != 1 && gondolaSeq[i - 1] + 1 != gondolaSeq[i])) return 0;
		sort(v.begin(), v.end());
		for(auto x : v){
			replacementSeq[l++] = x.second;
			while(ls < x.first)
				replacementSeq[l++] =ls++;
			ls++;
		}
	}else{
		sort(p , p + n);
		for(int i = 0 ; i < n ; ++i){
			replacementSeq[l++] = p[i].second;
			while(ls < p[i].first)
				replacementSeq[l++] =ls++;	
			ls++;
		}
	}
	return l ;
}

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

ll fastpower( ll x , ll n ){
	ll res = 1 ;
	while(n > 0){
		if(n % 2 == 1)
			res = (res * x) % M;
		x = ( x * x ) % M;
		n = n / 2 ;
	}
	return res;
}

int countReplacement(int n, int inputSeq[]){
	bool b = false ;
	for(int i = 0 ; i < n ; ++i){
		p[i] = {inputSeq[i] , i + 1};
		mp[inputSeq[i]]++;
		if(mp[inputSeq[i]] > 1)return 0;
		if(inputSeq[i] <= n){
			b = 1;
			int x = inputSeq[i];
			int f = i - 1;
			while(f > -1 && inputSeq[f] > n){
				x--;
				if(x == 0) x = n;
				v.push_back({inputSeq[f] , x});
				inputSeq[f] = x;
				mp[x]++;	
				if(mp[x] > 1) return 0 ;
				f--;
			}
			f = i + 1 ;
			x = inputSeq[i];
			while(f < n && inputSeq[f] > n){
				x++;
				if(x == n + 1) x = 1;
				v.push_back({inputSeq[f] , x});
				inputSeq[f] = x;
				mp[x]++;
				if(mp[x] > 1)return 0;
				f++;
			}
			i = f - 1;
		}
	}
	ll ans = 1 , ls = n + 1 , ans1 = 1;
	if(b){
		for(int i = 1 ; i < n ; ++i)
			if((inputSeq[i] == 1 && inputSeq[i - 1] != n) || (inputSeq[i] != 1 && inputSeq[i - 1] + 1 != inputSeq[i])) return 0;
		sort(v.begin(), v.end());
		int idx = 0 ;
		for(auto x : v){
			ans = (ans * fastpower(v.size() - idx , x.first - ls)) % M;
			ls = x.first + 1 ;
			idx++;
		}
	}else{
		sort(p , p + n);
		for(int i = 0 ; i < n - 1 ; ++i){
			ans = (ans * fastpower(n - i , p[i].first - ls)) % M;
			ls = p[i].first + 1;
		}
		ans = (ans * n) % M;
	}
	return ans ;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:173:28: warning: unused variable 'ans1' [-Wunused-variable]
  ll ans = 1 , ls = n + 1 , ans1 = 1;
                            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 19 ms 2424 KB Output is correct
7 Correct 17 ms 1144 KB Output is correct
8 Correct 32 ms 4344 KB Output is correct
9 Correct 13 ms 1656 KB Output is correct
10 Correct 39 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 20 ms 2424 KB Output is correct
7 Correct 17 ms 1144 KB Output is correct
8 Correct 32 ms 4344 KB Output is correct
9 Correct 13 ms 1656 KB Output is correct
10 Correct 40 ms 5116 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 10 ms 760 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 17 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 408 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 412 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 38 ms 5368 KB Output is correct
12 Correct 43 ms 6136 KB Output is correct
13 Correct 30 ms 3572 KB Output is correct
14 Correct 38 ms 5368 KB Output is correct
15 Correct 34 ms 3700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 45 ms 5616 KB Output is correct
10 Correct 35 ms 4720 KB Output is correct
11 Correct 17 ms 1908 KB Output is correct
12 Correct 18 ms 2292 KB Output is correct
13 Correct 8 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 46 ms 5616 KB Output is correct
10 Correct 34 ms 4720 KB Output is correct
11 Correct 17 ms 1908 KB Output is correct
12 Correct 18 ms 2292 KB Output is correct
13 Correct 9 ms 760 KB Output is correct
14 Correct 67 ms 5240 KB Output is correct
15 Correct 81 ms 5880 KB Output is correct
16 Correct 15 ms 1400 KB Output is correct
17 Correct 49 ms 4088 KB Output is correct
18 Correct 28 ms 2424 KB Output is correct