Submission #737658

# Submission time Handle Problem Language Result Execution time Memory
737658 2023-05-07T13:31:26 Z esomer Gondola (IOI14_gondola) C++17
75 / 100
43 ms 5100 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;
	}
	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++){
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 2344 KB Output is correct
7 Correct 10 ms 1108 KB Output is correct
8 Correct 28 ms 4248 KB Output is correct
9 Correct 8 ms 1492 KB Output is correct
10 Correct 30 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 12 ms 2388 KB Output is correct
7 Correct 11 ms 1164 KB Output is correct
8 Correct 22 ms 4300 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 29 ms 4968 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 15 ms 2232 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 38 ms 5100 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 212 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 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 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 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 960 KB Output is correct
12 Correct 9 ms 1084 KB Output is correct
13 Correct 13 ms 1432 KB Output is correct
14 Correct 8 ms 1004 KB Output is correct
15 Correct 19 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory 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 312 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 308 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory 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
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 43 ms 4680 KB Output is correct
10 Correct 33 ms 4016 KB Output is correct
11 Correct 11 ms 1620 KB Output is correct
12 Correct 15 ms 1964 KB Output is correct
13 Incorrect 3 ms 596 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 42 ms 4732 KB Output is correct
10 Correct 33 ms 3868 KB Output is correct
11 Correct 12 ms 1676 KB Output is correct
12 Correct 15 ms 1876 KB Output is correct
13 Incorrect 3 ms 708 KB Output isn't correct
14 Halted 0 ms 0 KB -