답안 #1001344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001344 2024-06-18T22:13:37 Z ZeroCool 곤돌라 (IOI14_gondola) C++14
100 / 100
40 ms 6488 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

int valid(int n, int A[]){
	int B[n];
	int p;
	
	set<int> s;
	for(int i = 0;i < n;i++)s.insert(A[i]);
	if(s.size() < n)return 0;
	
	for(int i = 0;i< n;i++){
		if(A[i] <= n){
			p = i;
			B[i] = A[i];
			break;
		}
	}
	
	for(int i = p + 1;i < n;i++){
		B[i] = B[i-1] + 1;
	}
	for(int i = p - 1;i >= 0;i--){
		B[i] = B[i + 1] - 1;
	}
	
	for(int i = 0;i < n;i ++){
		if(B[i] > n) B[i] -= n;
		if(B[i] <= 0) B[i] += n;
	}
	
	for(int i = 0;i<n;i++){
		if(A[i] > n)continue;
		if(A[i] != B[i])return 0;
	}
	
	return 1;
}

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

int replacement(int n, int A[], int ans[]){
	int o = 0;
	for(int i = 0;i < n;i++){
		if(A[i] > n)o++;
	}
	vector<ar<int, 2> > v;
	if(o == n){
		for(int i = 0;i < n;i++)v.push_back({A[i], i + 1});
	}else{
		int B[n];
		int p;
		
		for(int i = 0;i< n;i++){
			if(A[i] <= n){
				p = i;
				B[i] = A[i];
				break;
			}
		}
		
		for(int i = p + 1;i < n;i++){
			B[i] = B[i-1] + 1;
		}
		for(int i = p - 1;i >= 0;i--){
			B[i] = B[i + 1] - 1;
		}
		
		for(int i = 0;i < n;i ++){
			if(B[i] > n) B[i] -= n;
			if(B[i] <= 0) B[i] += n;
		}
		
		for(int i = 0;i < n;i++){
			if(A[i] > n)v.push_back({A[i], B[i]});
		}
		
		
	}
	sort(v.begin(), v.end());
	int c = n + 1;
	int cnt = 0;
	for(auto [x, i]: v){
		ans[cnt++] = i;
		while(c != x){
			ans[cnt++] = c++;
		}
		c++;
	}
	return cnt;
}

//----------------------
const int MOD = 1e9 + 9;
ll P(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b & 1)ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}
	return ans;
}

int countReplacement(int n, int A[]){
	if(!valid(n, A))return 0;
	ll ans = 1;
	vector<int> v;
	for(int i = 0;i < n;i++){
		if(A[i] > n)v.push_back(A[i]);
	}
	if(v.empty())return 1;
	sort(v.begin(), v.end());
	int m = v.size();
	
	ll c = n + 1;
	for(int i = 0;i < m;i++){
		int e = v[i] - c;
		if(m - i == n)e++;
		ans = (ans * P(m - i, e)) % MOD;
		c = v[i] + 1;
	}
	return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:15:14: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |  if(s.size() < n)return 0;
      |     ~~~~~~~~~^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:88:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   88 |  for(auto [x, i]: v){
      |           ^
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:25:10: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |  for(int i = p + 1;i < n;i++){
      |          ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:67:11: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |   for(int i = p + 1;i < n;i++){
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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
# 결과 실행 시간 메모리 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 7 ms 2396 KB Output is correct
7 Correct 17 ms 3944 KB Output is correct
8 Correct 11 ms 4188 KB Output is correct
9 Correct 3 ms 1508 KB Output is correct
10 Correct 17 ms 5208 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 6 ms 2396 KB Output is correct
7 Correct 18 ms 3928 KB Output is correct
8 Correct 13 ms 4188 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 16 ms 4956 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 8 ms 2304 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 20 ms 5008 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
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 5 ms 976 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 7 ms 1516 KB Output is correct
14 Correct 5 ms 860 KB Output is correct
15 Correct 11 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 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 348 KB Output is correct
8 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 1 ms 348 KB Output is correct
4 Correct 1 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 348 KB Output is correct
9 Correct 26 ms 4808 KB Output is correct
10 Correct 20 ms 3928 KB Output is correct
11 Correct 7 ms 1624 KB Output is correct
12 Correct 8 ms 2116 KB Output is correct
13 Correct 2 ms 600 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 420 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 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 24 ms 4760 KB Output is correct
10 Correct 21 ms 4148 KB Output is correct
11 Correct 7 ms 1628 KB Output is correct
12 Correct 8 ms 2116 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 30 ms 5832 KB Output is correct
15 Correct 40 ms 6488 KB Output is correct
16 Correct 5 ms 1572 KB Output is correct
17 Correct 28 ms 4532 KB Output is correct
18 Correct 11 ms 2648 KB Output is correct