답안 #1019508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019508 2024-07-11T01:51:44 Z pcc 곤돌라 (IOI14_gondola) C++17
100 / 100
45 ms 5980 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second

int valid(int n, int arr[]){
	int cen = -1;
	set<int> st;
	for(int i = 0;i<n;i++){
		if(arr[i]<=n)cen = i;
		if(st.find(arr[i]) != st.end())return false;
		st.insert(arr[i]);
	}
	if(cen == -1)return true;
	int c = arr[cen];
	while(cen<n){
		if(arr[cen] != c&&arr[cen]<=n)return false;
		c++;
		if(c>n)c -= n;
		cen++;
	}
	cen = 0;
	while(cen<n){
		if(arr[cen] != c&&arr[cen]<=n)return false;
		c++;
		if(c>n)c -= n;
		cen++;
	}
	return true;
}

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

int replacement(int n, int arr[], int ans[]){
	vector<pii> v;
	int ori = 0;
	for(int i = 0;i<n;i++){
		if(arr[i]>n)v.push_back(pii(arr[i],i));
		else ori = i;
	}
	if(ori != -1){
		int c = arr[ori];
		while(ori<n){
			arr[ori++] = c++;
			if(c>n)c -= n;
		}
		ori = 0;
		while(ori<n){
			arr[ori++] = c++;
			if(c>n)c -= n;
		}
	}
	sort(v.begin(),v.end());
	vector<int> re;
	int ptr = n;
	for(auto &i:v){
		while(ptr<i.fs){
			re.push_back(arr[i.sc]);
			arr[i.sc] = ++ptr;
		}
	}
	for(int i = 0;i<re.size();i++)ans[i] = re[i];
	return re.size();
}

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

const ll mod = 1e9+9;

ll pw(ll a,ll b){
	ll re = 1;
	while(b){
		if(b&1)re = re*a%mod;
		b>>=1;
		a = a*a%mod;
	}
	return re;
}
ll mad(ll a,ll b){
	a += b;
	return a>=mod?a-mod:a;
}
ll mub(ll a,ll b){
	return mad(a,mod-b);
}

int countReplacement(int n, int arr[]){
	if(!valid(n,arr))return 0;
	vector<pii> v;
	bool rot = true;
	for(int i = 0;i<n;i++){
		if(arr[i]>n)v.push_back(pii(arr[i],i));
		else rot = false;
	}
	//cerr<<"ROT: "<<rot<<endl;
	sort(v.rbegin(),v.rend());
	v.push_back(pii(n,-1));
	//cerr<<"V: ";for(auto &i:v)cerr<<i.fs<<' ';cerr<<endl;
	ll ans = 1;
	for(int i = 1;i<v.size();i++){
		ans = ans*pw(i,v[i-1].fs-v[i].fs-1)%mod;
	}
	if(rot)ans = ans*n%mod;
	return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for(int i = 0;i<re.size();i++)ans[i] = re[i];
      |                ~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:104:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |  for(int i = 1;i<v.size();i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 16 ms 3928 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 27 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 17 ms 3932 KB Output is correct
9 Correct 6 ms 1368 KB Output is correct
10 Correct 22 ms 4564 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 14 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 28 ms 4680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 5 ms 856 KB Output is correct
13 Correct 9 ms 1372 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 13 ms 2356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 444 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 440 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 35 ms 4444 KB Output is correct
10 Correct 24 ms 3680 KB Output is correct
11 Correct 8 ms 1632 KB Output is correct
12 Correct 11 ms 2004 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
9 Correct 32 ms 4584 KB Output is correct
10 Correct 26 ms 3932 KB Output is correct
11 Correct 8 ms 1632 KB Output is correct
12 Correct 11 ms 1884 KB Output is correct
13 Correct 2 ms 756 KB Output is correct
14 Correct 37 ms 5500 KB Output is correct
15 Correct 45 ms 5980 KB Output is correct
16 Correct 7 ms 1372 KB Output is correct
17 Correct 28 ms 4440 KB Output is correct
18 Correct 14 ms 2904 KB Output is correct