Submission #737611

# Submission time Handle Problem Language Result Execution time Memory
737611 2023-05-07T12:29:20 Z esomer Gondola (IOI14_gondola) C++17
20 / 100
38 ms 5056 KB
#include<bits/stdc++.h>
#include "gondola.h"
 
using namespace std;
 
const int MOD = 1e9 + 7;
 
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;
		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;
	for(int x : v){
		ans *= pw(broken, x - lst); ans %= MOD;
		broken--; lst = x;
	}
	return (int)ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:6: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |  int ind;
      |      ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:89:10: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |  for(int i = ind + 1; i % n != ind; i++){
      |          ^
# 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 1 ms 304 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 212 KB Output is correct
6 Correct 13 ms 2388 KB Output is correct
7 Correct 8 ms 1088 KB Output is correct
8 Correct 24 ms 4240 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 29 ms 4992 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 2380 KB Output is correct
7 Correct 9 ms 1064 KB Output is correct
8 Correct 21 ms 4260 KB Output is correct
9 Correct 7 ms 1468 KB Output is correct
10 Correct 33 ms 4908 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 16 ms 2444 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 38 ms 5056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Integer 3 violates the range [1, 2]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Integer 3 violates the range [1, 2]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 1 ms 304 KB Integer 3 violates the range [1, 2]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -