Submission #254536

# Submission time Handle Problem Language Result Execution time Memory
254536 2020-07-30T08:05:01 Z b00n0rp Gondola (IOI14_gondola) C++17
100 / 100
67 ms 5112 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long

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

//----------------------
int a[100005];

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	bool flag = 0;
	for(int i = 0; i < n; i ++){
		a[i] = gondolaSeq[i];
		flag |= (a[i] <= n);
	}
	// for(int i = 0; i < n; i ++){
	// 	cout << i << " - " << a[i] << endl;
	// }
	if(!flag) a[0] = 1;
	// for(int i = 0; i < n; i ++){
	// 	cout << i << " - " << a[i] << endl;
	// }

	for(int i = 0; i < n; i ++){
		if(a[i] <= n){
			// cout << i << endl;
			for(int j = (i+1)%n; j != i; j = (j+1)%n){
				a[j] = (a[i]+(j-i)+n-1)%n + 1;
			}
			break;
		}
	}
	// for(int i = 0; i < n; i ++){
	// 	cout << i << " - " << a[i] << endl;
	// }
	vector<pair<int,int> > v;
	for(int i = 0; i < n; i ++){
		if(gondolaSeq[i] <= n) continue;
		v.push_back({gondolaSeq[i],a[i]});
	}
	sort(v.begin(),v.end());
	int cur = n+1,ind = 0;
	for(int i = 0; i < v.size(); i ++){
		replacementSeq[ind++] = v[i].second;
		while(cur < v[i].first){
			replacementSeq[ind++] = cur++;
		}
		cur++;
	}
	return ind;
}

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

const ll MOD = 1000000009;

ll power(int x,int y){
	if(y == 0) return 1;
	if(y == 1) return x;
	ll cur = power(x,y/2);
	cur = (cur*cur)%MOD;
	if(y%2) cur = (cur*x)%MOD;
	return cur;
}

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

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:12:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(s.size() != n) return 0;
     ~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:61:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i ++){
                 ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:95:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(v.size() == n) ans = n;
     ~~~~~~~~~^~~~
gondola.cpp:97:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < v.size(); i ++){
                 ~~^~~~~~~~~~
gondola.cpp:87:6: warning: unused variable 'cur' [-Wunused-variable]
  int cur = 0;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 2176 KB Output is correct
7 Correct 30 ms 3664 KB Output is correct
8 Correct 22 ms 3968 KB Output is correct
9 Correct 7 ms 1408 KB Output is correct
10 Correct 28 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 12 ms 2176 KB Output is correct
7 Correct 31 ms 3712 KB Output is correct
8 Correct 23 ms 3968 KB Output is correct
9 Correct 8 ms 1536 KB Output is correct
10 Correct 27 ms 4608 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 17 ms 2048 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 47 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 11 ms 1408 KB Output is correct
12 Correct 13 ms 1536 KB Output is correct
13 Correct 15 ms 1680 KB Output is correct
14 Correct 11 ms 1408 KB Output is correct
15 Correct 22 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 39 ms 4088 KB Output is correct
10 Correct 31 ms 3448 KB Output is correct
11 Correct 12 ms 1408 KB Output is correct
12 Correct 14 ms 1664 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 43 ms 4036 KB Output is correct
10 Correct 44 ms 3448 KB Output is correct
11 Correct 12 ms 1408 KB Output is correct
12 Correct 14 ms 1664 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 67 ms 4508 KB Output is correct
15 Correct 63 ms 5112 KB Output is correct
16 Correct 10 ms 1152 KB Output is correct
17 Correct 36 ms 3584 KB Output is correct
18 Correct 20 ms 2176 KB Output is correct