답안 #737660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737660 2023-05-07T13:33:58 Z esomer 곤돌라 (IOI14_gondola) C++17
100 / 100
61 ms 6328 KB
#include<bits/stdc++.h>
#include "gondola.h"
 
using namespace std;

const int MOD = 1e9 + 9;

//~ 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;
	}
	if(mn > n) ans = (ans * n) % MOD;
	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: In function 'int valid(int, int*)':
gondola.cpp:27:6: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |  int ind;
      |      ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:96:10: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |  for(int i = ind + 1; i % n != ind; i++){
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 12 ms 2260 KB Output is correct
7 Correct 8 ms 724 KB Output is correct
8 Correct 21 ms 4052 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 29 ms 4592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 8 ms 724 KB Output is correct
8 Correct 22 ms 3972 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 29 ms 4556 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 15 ms 2112 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 41 ms 4768 KB Output is correct
# 결과 실행 시간 메모리 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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
# 결과 실행 시간 메모리 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 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 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 6 ms 724 KB Output is correct
12 Correct 7 ms 724 KB Output is correct
13 Correct 13 ms 1356 KB Output is correct
14 Correct 7 ms 684 KB Output is correct
15 Correct 19 ms 2344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 40 ms 4296 KB Output is correct
10 Correct 32 ms 3596 KB Output is correct
11 Correct 11 ms 1620 KB Output is correct
12 Correct 14 ms 1876 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 40 ms 4192 KB Output is correct
10 Correct 30 ms 3536 KB Output is correct
11 Correct 12 ms 1488 KB Output is correct
12 Correct 13 ms 1748 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 48 ms 5620 KB Output is correct
15 Correct 61 ms 6328 KB Output is correct
16 Correct 10 ms 1340 KB Output is correct
17 Correct 38 ms 4352 KB Output is correct
18 Correct 22 ms 2616 KB Output is correct