Submission #1025766

# Submission time Handle Problem Language Result Execution time Memory
1025766 2024-07-17T09:46:15 Z socpite Gondola (IOI14_gondola) C++17
100 / 100
46 ms 5964 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 3e5+5;
const int mod = 1e9+9;

long long binpow(long long x, int e){
	long long re = 1;
	while(e){
		if(e&1)re = re*x%mod;
		x = x*x%mod;
		e>>=1;
	}
	return re;
}

int valid(int n, int inputSeq[])
{
	map<int, int> vis;
	int dist = -1;
	for(int i = 0; i < n; i++)inputSeq[i]--;
	for(int i = 0; i < n; i++){
		if(vis[inputSeq[i]])return 0;
		vis[inputSeq[i]] = 1;
		if(inputSeq[i] < n){
			int d = (i + n - inputSeq[i])%n;
			if(dist == -1)dist = d;
			else if(dist != d)return 0;
		}
	}
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	vector<pair<int, int>> vec;
	int dist = 0;
	for(int i = 0; i < n; i++){
		gondolaSeq[i]--;
		if(gondolaSeq[i] < n){
			dist = (gondolaSeq[i] - i + n)%n;
		}
		else {
			vec.push_back({gondolaSeq[i], i});
		}
	}
	int crr = 0;
	sort(vec.begin(), vec.end());
	for(auto v: vec){
		replacementSeq[crr++] = (v.second + dist)%n + 1;
		while(crr+n <= v.first){
			replacementSeq[crr] = crr + n;
			crr++;
		}
	}
	return crr;
}

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

int countReplacement(int n, int inputSeq[])
{
	if(!valid(n, inputSeq))return 0;
	vector<int> vec;
	int dist = 0;
	for(int i = 0; i < n; i++){
		if(inputSeq[i] >= n)vec.push_back(inputSeq[i]);
	}
	int prv = n-1;
	sort(vec.begin(), vec.end());
	int sz = vec.size();
	long long ans = 1;
	for(int i = 0; i < sz; i++){
		ans = ans*binpow(sz - i, vec[i] - prv-1)%mod;
		prv = vec[i];
	}
	if(sz == n)ans = ans*n%mod;
	return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:68:6: warning: unused variable 'dist' [-Wunused-variable]
   68 |  int dist = 0;
      |      ^~~~
# 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 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 2140 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 19 ms 3828 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 21 ms 4444 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 1 ms 344 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 3852 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
10 Correct 21 ms 4580 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 5 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 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 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
# 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 344 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
11 Correct 5 ms 604 KB Output is correct
12 Correct 5 ms 792 KB Output is correct
13 Correct 8 ms 1260 KB Output is correct
14 Correct 5 ms 564 KB Output is correct
15 Correct 14 ms 2388 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 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 0 ms 344 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 31 ms 4176 KB Output is correct
10 Correct 25 ms 3420 KB Output is correct
11 Correct 9 ms 1372 KB Output is correct
12 Correct 12 ms 1628 KB Output is correct
13 Correct 3 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 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 31 ms 3920 KB Output is correct
10 Correct 24 ms 3420 KB Output is correct
11 Correct 9 ms 1576 KB Output is correct
12 Correct 11 ms 1628 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 40 ms 5456 KB Output is correct
15 Correct 46 ms 5964 KB Output is correct
16 Correct 7 ms 1368 KB Output is correct
17 Correct 29 ms 4060 KB Output is correct
18 Correct 16 ms 2396 KB Output is correct