Submission #533918

# Submission time Handle Problem Language Result Execution time Memory
533918 2022-03-07T15:38:30 Z M_W Gondola (IOI14_gondola) C++11
100 / 100
37 ms 5880 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define ii pair<int, int>
using namespace std;
unordered_map<int, bool> mark;

int valid(int n, int inputSeq[])
{
	int idx = 0;
	for(int i = 0; i < n; i++){
		if(mark[inputSeq[i]]) return 0;
		mark[inputSeq[i]] = true;
		
		if(idx == 0 && inputSeq[i] <= n){
			idx = inputSeq[i];
		}
		if(idx != 0 && inputSeq[i] <= n && inputSeq[i] != idx) return 0;
		if(idx != 0) idx++;
		if(idx > n) idx = 1;
	}
	return 1;
}

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

int a[100001];

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int idx = 0;
	priority_queue<ii, vector<ii>, greater<ii> > pq;
	for(int i = 0; i < n; i++){
		if(gondolaSeq[i] > n){
			pq.push({gondolaSeq[i], i});
		}
		if(idx == 0 && gondolaSeq[i] <= n){
			idx = gondolaSeq[i];
			
			for(int j = i - 1, tmp = idx - 1; j >= 0; j--, tmp--){
				if(tmp <= 0) tmp += n;
				a[j] = tmp;
			}
		}
		if(idx != 0){
			a[i] = idx;
			idx++;
		} 
		if(idx > n) idx = 1;
	}
	if(idx == 0){
		for(int i = 0; i < n; i++) a[i] = i + 1;
	}
	
	int replace_idx = n + 1, ans_idx = 0;
	while(!pq.empty()){
		int k = pq.top().first;
		int id = pq.top().second;
		pq.pop();
		
		while(replace_idx <= k){
			replacementSeq[ans_idx++] = a[id];
			a[id] = replace_idx;
			replace_idx++;
		}
	}
	return ans_idx;
}

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

const long long md = 1e9 + 9;
long long pw(long long a, long long b){
	if(b == 0) return 1ll;
	if(b == 1) return a;
	
	long long e = pw(a, b >> 1);
	if(b % 2) return ((e * e) % md) * a % md;
	return (e * e) % md;
}

int countReplacement(int n, int inputSeq[])
{
	if(valid(n, inputSeq) == 0) return 0;
	long long ans = 1, chk = 0;
	priority_queue<int, vector<int>, greater<int> > pq;
	for(int i = 0; i < n; i++){
		if(inputSeq[i] > n) pq.push(inputSeq[i]);
		else chk = 1;
	}
	
	if(!chk) ans = n * 1ll;
	if(pq.empty()) return 1;
	pq.push(n);
	
	while(pq.size() > 1){
		int u = pq.top(); pq.pop();
		int v = pq.top();
		
		ans = (ans * pw(pq.size() * 1ll, (v - u - 1) * 1ll)) % md;
	}
	return int(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 6 ms 1960 KB Output is correct
7 Correct 7 ms 588 KB Output is correct
8 Correct 10 ms 3416 KB Output is correct
9 Correct 4 ms 1484 KB Output is correct
10 Correct 12 ms 3888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 6 ms 1960 KB Output is correct
7 Correct 8 ms 576 KB Output is correct
8 Correct 11 ms 3448 KB Output is correct
9 Correct 5 ms 1484 KB Output is correct
10 Correct 12 ms 3868 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 7 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 7 ms 844 KB Output is correct
12 Correct 10 ms 972 KB Output is correct
13 Correct 13 ms 1340 KB Output is correct
14 Correct 6 ms 844 KB Output is correct
15 Correct 18 ms 2312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 23 ms 3960 KB Output is correct
10 Correct 18 ms 3548 KB Output is correct
11 Correct 8 ms 1576 KB Output is correct
12 Correct 9 ms 1832 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 24 ms 4032 KB Output is correct
10 Correct 18 ms 3504 KB Output is correct
11 Correct 7 ms 1532 KB Output is correct
12 Correct 9 ms 1832 KB Output is correct
13 Correct 2 ms 588 KB Output is correct
14 Correct 31 ms 4704 KB Output is correct
15 Correct 37 ms 5880 KB Output is correct
16 Correct 6 ms 1228 KB Output is correct
17 Correct 22 ms 3648 KB Output is correct
18 Correct 12 ms 2216 KB Output is correct