Submission #126802

# Submission time Handle Problem Language Result Execution time Memory
126802 2019-07-08T12:38:32 Z ekrem Gondola (IOI14_gondola) C++
90 / 100
60 ms 2816 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000009
#define inf 1000000009
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, m, mx, a[N], u[N], b[N];


int valid(int n, int a[]){
	int x = inf;
	for(int i = 0; i < n; i++){
		a[i]--;
		if(u[a[i]])return 0;
		u[a[i]] = 1;
		if(a[i] < n and a[i] >= 0){
			if(x != inf and x != (a[i] - i + n)%n )
				return 0;
			x = (a[i] - i + n)%n;
		}
	}
	return 1;
}

int replacement(int n, int a[], int b[]){
	int m = -1, x = 0;
	priority_queue < ii > q;
	priority_queue < int > yok;
	for(int i = 0; i < n; i++){
		a[i]--;
		u[a[i]] = 1;
		mx = max(mx, a[i]);
		if(a[i] < n and a[i] >= 0)
			x = (a[i] - i + n)%n;
		else
			q.push(mp(a[i], i));
	}
	for(int i = n; i <= mx; i++)
		if(!u[i])
			yok.push(i);
	while(!q.empty()){
		int y = q.top().st;
		int ind = q.top().nd;
		q.pop();
		if(yok.empty())
			b[++m] = (x + ind)%n + 1;
		else{
			b[++m] = yok.top() + 1;
			q.push(mp(yok.top(), ind));
			yok.pop();
		}
	}
	reverse(b, b + m + 1);
	// for(int i = 0; i <= m; i++)
	// 	cout << "b"<<b[i] << " ";
 	return m + 1;
}

ll fe(ll a, ll us){
	if(us <= 1)
		return (us)?a:1ll;
	ll t = fe(a, us/2);
	return (us&1)?(t*t%mod)*a%mod : t*t%mod;
}

int countReplacement(int n, int a[]){
	ll x = n, say = 0, ans = 1;
	for(int i = 0; i < n; i++){
		u[a[i]] = 1;
		mx = max(mx, a[i]);
		if(a[i] <= n)
			x = 1;
		else
			b[++m] = a[i];
	}
	sort(b + 1, b + m + 1);
	b[0] = n;
	for(int i = 1; i <= m; i++){
		ans = ans*fe(m - i + 1, b[i] - b[i - 1] - 1)%mod;
	}
 	return ans*x%mod;
}




// int gondolaSequence[100001];
// int replacementSequence[250001];
// int main()
// {
// freopen("in.txt", "r", stdin);
// freopen("outt.txt", "w", stdout);
// int i, n, tag;
// int nr; 
// assert(scanf("%d", &tag)==1);
// assert(scanf("%d", &n)==1);
// for(i=0;i< n;i++)
// assert( scanf("%d", &gondolaSequence[i]) ==1);

// switch (tag){
// case 1: case 2: case 3:
// printf("%d\n", valid(n, gondolaSequence));
// break;

// case 4: case 5: case 6:
// nr = replacement(n, gondolaSequence, replacementSequence);
// printf("%d ", nr);
// if (nr > 0)
// {
// for (i=0; i<nr-1; i++)
// printf("%d ", replacementSequence[i]);
// printf("%d\n", replacementSequence[nr-1]);
// }  
// else printf("\n");
// break;

// case 7: case 8: case 9: case 10:
// printf("%d\n",  countReplacement(n, gondolaSequence));  
// break;
// }

// return 0;
// }

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:54:7: warning: unused variable 'y' [-Wunused-variable]
   int y = q.top().st;
       ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:79:12: warning: unused variable 'say' [-Wunused-variable]
  ll x = n, say = 0, ans = 1;
            ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 7 ms 632 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 11 ms 888 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 12 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 7 ms 632 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 11 ms 888 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 12 ms 1016 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 7 ms 760 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 15 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 372 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 12 ms 1016 KB Output is correct
12 Correct 15 ms 988 KB Output is correct
13 Correct 32 ms 1780 KB Output is correct
14 Correct 14 ms 972 KB Output is correct
15 Correct 60 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 19 ms 1528 KB Output is correct
10 Correct 15 ms 1272 KB Output is correct
11 Correct 8 ms 1144 KB Output is correct
12 Correct 9 ms 1016 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 19 ms 1528 KB Output is correct
10 Correct 15 ms 1272 KB Output is correct
11 Correct 8 ms 1148 KB Output is correct
12 Correct 9 ms 1044 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Runtime error 17 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -