Submission #128127

# Submission time Handle Problem Language Result Execution time Memory
128127 2019-07-10T12:51:02 Z nxteru Gondola (IOI14_gondola) C++14
100 / 100
90 ms 7284 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
#define PB push_back
#define M 1000000009LL
ll pw(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1)res=res*x%M;
		y>>=1;
		x=x*x%M;
	}
	return res;
}
int n,x[100005];
set<int>p;
int valid(int N,int a[]){
	n=N;
	int b=-1,c;
	for(int i=0;i<n;i++){
		if(a[i]<=n){
			if(b!=-1&&(b+i-c)%n+1!=a[i])return 0;
			b=a[i]-1,c=i;
		}else{
			if(p.find(a[i])!=p.end())return 0;
			p.insert(a[i]);
		}
	}
	return 1;
}

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

int replacement(int N,int a[],int r[]){
	n=N;
	int b=0,c=0;
	for(int i=0;i<n;i++)if(a[i]<=n)b=a[i]-1,c=i;
	for(int i=0;i<n;i++){
		x[(c+i)%n]=(b+i)%n+1;
	}
	vector<P>g;
	for(int i=0;i<n;i++)if(a[i]>n)g.PB(P(a[i],i));
	sort(g.begin(),g.end());
	int d=n+1,k=0;
	for(int i=0;i<g.size();i++){
		int q=g[i].S;
		while(x[q]<a[q]){
			r[k++]=x[q];
			x[q]=d++;
		}
	}
	return k;
}

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

int countReplacement(int N,int a[]){
	n=N;
	if(valid(n,a)==0)return 0;
	vector<P>g;
	for(int i=0;i<n;i++)if(a[i]>n)g.PB(P(a[i],i));
	sort(g.begin(),g.end());
	ll u=n,s=g.size(),ans=1LL;
	for(ll i=0;i<s;i++){
		ll t=g[i].F;
		ans=ans*pw(s-i,t-u-1LL)%M;
		u=t;
	}
	if(s==n)ans=ans*ll(n)%M;
	return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g.size();i++){
              ~^~~~~~~~~
# 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 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 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 380 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 7 ms 504 KB Output is correct
7 Correct 14 ms 636 KB Output is correct
8 Correct 11 ms 632 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 12 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 6 ms 508 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 11 ms 632 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 12 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 14 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 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 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 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 256 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 2 ms 376 KB Output is correct
10 Correct 3 ms 380 KB Output is correct
11 Correct 13 ms 1016 KB Output is correct
12 Correct 14 ms 1020 KB Output is correct
13 Correct 18 ms 1404 KB Output is correct
14 Correct 12 ms 1016 KB Output is correct
15 Correct 23 ms 2404 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 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 420 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 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 52 ms 3956 KB Output is correct
10 Correct 39 ms 3188 KB Output is correct
11 Correct 18 ms 2040 KB Output is correct
12 Correct 21 ms 2040 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 52 ms 3956 KB Output is correct
10 Correct 40 ms 3316 KB Output is correct
11 Correct 17 ms 1912 KB Output is correct
12 Correct 21 ms 2040 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
14 Correct 81 ms 6644 KB Output is correct
15 Correct 90 ms 7284 KB Output is correct
16 Correct 15 ms 1784 KB Output is correct
17 Correct 61 ms 4856 KB Output is correct
18 Correct 30 ms 3196 KB Output is correct