Submission #980965

# Submission time Handle Problem Language Result Execution time Memory
980965 2024-05-12T16:27:45 Z SmuggingSpun Gondola (IOI14_gondola) C++14
100 / 100
51 ms 5972 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]){
	vector<pair<int, int>>p;
	map<int, bool>cnt;
	for(int i = 0; i < n; i++){
		if(inputSeq[i] <= n){
			p.emplace_back(inputSeq[i], i);
		}
		else if(cnt[inputSeq[i]]){
			return 0;
		}
		else{
			cnt[inputSeq[i]] = true;
		}
	}	
	sort(p.begin(), p.end());
	for(int i = 1; i < p.size(); i++){
		if((p[i].second < p[i - 1].second && (p[i].second += n) < p[i - 1].second) || (p[i].second - p[i - 1].second != p[i].first - p[i - 1].first)){
			return 0;
		}
	}
	return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	if(valid(n, gondolaSeq) == 0){
		return 0;
	}
	int index = min_element(gondolaSeq, gondolaSeq + n) - gondolaSeq, L = 0;
	if(gondolaSeq[index] > n){
		vector<int>p(n), init(n);
		iota(p.begin(), p.end(), 0);
		iota(init.begin(), init.end(), 1);
		sort(p.begin(), p.end(), [&] (int i, int j) -> bool{
			return gondolaSeq[i] < gondolaSeq[j];
		});
		int current = n;
		for(int& i : p){
			while(gondolaSeq[i] > init[i]){
				replacementSeq[L++] = init[i];
				init[i] = ++current;
			}
		}
	}
	else{
		vector<int>init(n);
		for(int i = 0; i < n; i++){
			init[(i + index) % n] = (gondolaSeq[index] - 1 + i) % n + 1;
		}
		vector<int>p;
		for(int i = 0; i < n; i++){
			if(gondolaSeq[i] > n){
				p.emplace_back(i);
			}
		}
		sort(p.begin(), p.end(), [&] (int i, int j) -> bool{
			return gondolaSeq[i] < gondolaSeq[j];
		});
		int current = n;
		for(int& i : p){
			while(gondolaSeq[i] > init[i]){
				replacementSeq[L++] = init[i];
				init[i] = ++current;
			}
		}
	}
	return L;
}
const int mod = 1e9 + 9;
int power(int a, int b){
	int ans = 1;
	for(; b > 0; b >>= 1, a = 1LL * a * a % mod){
		if(b & 1){
			ans = 1LL * ans * a % mod;
		}
	}
	return ans;
}
int countReplacement(int n, int inputSeq[]){
	if(valid(n, inputSeq) == 0){
		return 0;
	}
	vector<int>p;
	for(int i = 0; i < n; i++){
		if(inputSeq[i] > n){
			p.emplace_back(i);
		}
	}
	sort(p.begin(), p.end(), [&] (int i, int j) -> bool{
		return inputSeq[i] < inputSeq[j];
	});
	int ans = (p.size() == n ? n : 1);
	for(int i = 0, pre = n; i < p.size(); pre = inputSeq[p[i++]]){
		ans = 1LL * ans * power(int(p.size()) - i, inputSeq[p[i]] - pre - 1) % mod;
	}
	return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 1; i < p.size(); i++){
      |                 ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:93:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   93 |  int ans = (p.size() == n ? n : 1);
      |             ~~~~~~~~~^~~~
gondola.cpp:94:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for(int i = 0, pre = n; i < p.size(); pre = inputSeq[p[i++]]){
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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
# Verdict Execution time Memory 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 1240 KB Output is correct
7 Correct 14 ms 1808 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 13 ms 1744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1240 KB Output is correct
7 Correct 13 ms 1708 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 3 ms 744 KB Output is correct
10 Correct 12 ms 1748 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 360 KB Output is correct
13 Correct 15 ms 2136 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 17 ms 2192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 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
# Verdict Execution time Memory 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 476 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 9 ms 1768 KB Output is correct
12 Correct 13 ms 1944 KB Output is correct
13 Correct 21 ms 2652 KB Output is correct
14 Correct 9 ms 1748 KB Output is correct
15 Correct 20 ms 2920 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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
# Verdict Execution time Memory 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 1 ms 500 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 30 ms 3892 KB Output is correct
10 Correct 22 ms 3160 KB Output is correct
11 Correct 10 ms 1880 KB Output is correct
12 Correct 12 ms 1884 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 29 ms 3912 KB Output is correct
10 Correct 24 ms 3160 KB Output is correct
11 Correct 10 ms 1628 KB Output is correct
12 Correct 12 ms 1928 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 43 ms 5456 KB Output is correct
15 Correct 51 ms 5972 KB Output is correct
16 Correct 8 ms 1372 KB Output is correct
17 Correct 32 ms 4180 KB Output is correct
18 Correct 17 ms 2396 KB Output is correct