Submission #737652

# Submission time Handle Problem Language Result Execution time Memory
737652 2023-05-07T13:23:49 Z esomer Gondola (IOI14_gondola) C++17
60 / 100
39 ms 5112 KB
#include<bits/stdc++.h>
#include "gondola.h"
 
using namespace std;

const int MOD = 1e9 + 7;

//~ 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 1 ms 340 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 1 ms 256 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 224 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 2388 KB Output is correct
7 Correct 10 ms 1056 KB Output is correct
8 Correct 24 ms 4352 KB Output is correct
9 Correct 8 ms 1492 KB Output is correct
10 Correct 33 ms 5000 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 308 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 2388 KB Output is correct
7 Correct 10 ms 1080 KB Output is correct
8 Correct 24 ms 4320 KB Output is correct
9 Correct 8 ms 1472 KB Output is correct
10 Correct 33 ms 4924 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 17 ms 2260 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 39 ms 5112 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 1 ms 308 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
6 Correct 1 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 340 KB Output is correct
10 Correct 1 ms 308 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 312 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 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 12 ms 980 KB Output is correct
12 Correct 10 ms 1092 KB Output is correct
13 Correct 14 ms 1468 KB Output is correct
14 Correct 13 ms 992 KB Output is correct
15 Correct 21 ms 2360 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 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 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 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 292 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 260 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 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 304 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -