Submission #1015282

# Submission time Handle Problem Language Result Execution time Memory
1015282 2024-07-06T08:21:58 Z parsadox2 Gondola (IOI14_gondola) C++17
100 / 100
36 ms 6356 KB
#include "gondola.h"

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

const int mod = 1e9 + 9;

int valid(int n, int inputSeq[])
{
	int mn_pos = 0;
	for(int i = 1 ; i < n ; i++)  if(inputSeq[i] < inputSeq[mn_pos])
		mn_pos = i;
	vector <int> vec;
	for(int i = mn_pos ; i < n ; i++)
		vec.push_back(inputSeq[i]);
	for(int i = 0 ; i < mn_pos ; i++)
		vec.push_back(inputSeq[i]);
	set <int> st;
	for(auto u : vec)
		st.insert(u);
	if(st.size() != n)
		return 0;
	bool flg = true;
	for(int i = 1 ; i < n ; i++)  if(vec[i] <= n && vec[i] - vec[0] != i)
		flg = false;
	return flg;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int mn_pos = 0;
	for(int i = 1 ; i < n ; i++)  if(gondolaSeq[i] < gondolaSeq[mn_pos])
		mn_pos = i;
	vector <int> vec;
	for(int i = mn_pos ; i < n ; i++)
		vec.push_back(gondolaSeq[i]);
	for(int i = 0 ; i < mn_pos ; i++)
		vec.push_back(gondolaSeq[i]);
	int mx = 0;
	for(int i = 0 ; i < n ; i++)
		mx = max(mx , vec[i]);
	int l = mx - n , pos = 0 , las = n;
	vector <pair<int , int>> bad;
	for(int i = 0 ; i < n ; i++)  if(vec[i] > n)
		bad.push_back(make_pair(vec[i] , i));
	if(vec[0] > n)
		vec[0] = 1;
	for(int i = 1 ; i < n ; i++)
	{
		vec[i] = vec[i - 1] + 1;
		if(vec[i - 1] == n)
			vec[i] = 1;
	}
	sort(bad.begin() , bad.end());
	for(auto u : bad)
	{
		while(las < u.F)
		{
			las++;
			replacementSeq[pos] = vec[u.S];
			vec[u.S] = las;
			pos++;
		}
	}
	return l;
}

int tav(int a , int b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)
			res = 1LL * res * a % mod;
		b >>= 1;
		a = 1LL * a * a % mod;
	}
	return res;
}

int countReplacement(int n, int inputSeq[])
{
	if(!valid(n , inputSeq))
		return 0;
	vector <int> vec;
	for(int i = 0 ; i < n ; i++)  if(inputSeq[i] > n)
		vec.push_back(inputSeq[i]);
	int x = vec.size();
	sort(vec.begin() , vec.end());
	int ans = 1 , las = n;
	for(auto u : vec)
	{
		ans = 1LL * ans * tav(x , u - las - 1) % mod;
		las = u;
		x--;
	}
	if(vec.size() == n)
		ans = 1LL * ans * n % mod;
	return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:15: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |  if(st.size() != n)
      |     ~~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:99:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   99 |  if(vec.size() == n)
      |     ~~~~~~~~~~~^~~~
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 2520 KB Output is correct
7 Correct 20 ms 4564 KB Output is correct
8 Correct 15 ms 4616 KB Output is correct
9 Correct 5 ms 1624 KB Output is correct
10 Correct 18 ms 5276 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 444 KB Output is correct
6 Correct 8 ms 2516 KB Output is correct
7 Correct 26 ms 4612 KB Output is correct
8 Correct 15 ms 4564 KB Output is correct
9 Correct 5 ms 1628 KB Output is correct
10 Correct 20 ms 5332 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 10 ms 2416 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 25 ms 5488 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 360 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 1 ms 348 KB Output is correct
10 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 344 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 1752 KB Output is correct
12 Correct 6 ms 1752 KB Output is correct
13 Correct 8 ms 1512 KB Output is correct
14 Correct 5 ms 1752 KB Output is correct
15 Correct 10 ms 2320 KB Output is correct
# Verdict Execution time Memory 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
# 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 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 1 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 23 ms 4820 KB Output is correct
10 Correct 21 ms 3944 KB Output is correct
11 Correct 7 ms 1628 KB Output is correct
12 Correct 9 ms 1884 KB Output is correct
13 Correct 2 ms 604 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
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 444 KB Output is correct
9 Correct 23 ms 4940 KB Output is correct
10 Correct 19 ms 4056 KB Output is correct
11 Correct 6 ms 1628 KB Output is correct
12 Correct 9 ms 1884 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 33 ms 5620 KB Output is correct
15 Correct 36 ms 6356 KB Output is correct
16 Correct 6 ms 1372 KB Output is correct
17 Correct 23 ms 4316 KB Output is correct
18 Correct 13 ms 2756 KB Output is correct