Submission #340486

# Submission time Handle Problem Language Result Execution time Memory
340486 2020-12-27T17:48:46 Z Kerim Gondola (IOI14_gondola) C++17
100 / 100
72 ms 6124 KB
#include "gondola.h"
#include "bits/stdc++.h"
#define MAXN 300009
#define INF 1000000009
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
map<int,int>mark;
int valid(int n, int arr[]){
	mark.clear();int mn=INF,who,res=1;
	for(int i=0;i<n;i++){
		if(mark[arr[i]])return 0;
		if(umin(mn,arr[i]))who=i;
		mark[arr[i]]=1;
	}
	if(mn>n)return 1;
	for(int i=0;i<n;i++)
		res&=((arr[(who+i)%n]>n) or arr[(who+i)%n]==mn+i);	
  	return res;
}

//----------------------
int vis[MAXN];
int replacement(int n, int arr[], int ans[]){
  	assert(valid(n,arr));
  	int mn=INF,mx=0,who,am;
  	for(int i=0;i<n;i++){
  		if(umin(mn,arr[i]))who=i;
  		umax(mx,arr[i]);
  	}
  	if(mx<=n)return 0;
  	if(mn>n)who=0,mn=1;
  	who=(who-(mn-1)+n)%n;
  	int last,res=0;
	for(int i=0;i<n;i++){
		int to=(who+i)%n;
		if(arr[to]>n){
			if(arr[to]==mx)last=i+1;	
			else vis[arr[to]]=i+1;
		}
	}
	for(int i=n+1;i<=mx;i++){
		if(!vis[i])ans[res++]=last,last=i;
		else ans[res++]=vis[i];
	}
	return res;
}

//----------------------
int mod(ll x){
	return (x%INF);
}
int Fe(int x,int y){
	if(!y)return 1;
	int h=Fe(x,y/2);
	h=mod(h*1LL*h);
	if(y&1)h=mod(h*1LL*x);
	return h;	
}
int countReplacement(int n, int arr[]){
	if(!valid(n,arr))return 0;
	sort(arr,arr+n);int ans=1,cnt=0;
	for(int j=0;j<n;j++)cnt+=(arr[j]>n);
	if(arr[0]>n)ans=mod(n*1LL*Fe(cnt,arr[0]-n-1)),cnt--;
	for(int i=0;i<n-1;i++)if(arr[i+1]>n)ans=mod(ans*1LL*Fe(cnt--,arr[i+1]-max(n,arr[i])-1));
	return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:39:24: warning: unused variable 'am' [-Wunused-variable]
   39 |    int mn=INF,mx=0,who,am;
      |                        ^~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:26: warning: 'who' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |  mark.clear();int mn=INF,who,res=1;
      |                          ^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:56:24: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |   if(!vis[i])ans[res++]=last,last=i;
      |              ~~~~~~~~~~^~~~~
gondola.cpp:39:20: warning: 'who' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |    int mn=INF,mx=0,who,am;
      |                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 15 ms 2412 KB Output is correct
7 Correct 11 ms 1132 KB Output is correct
8 Correct 33 ms 4332 KB Output is correct
9 Correct 9 ms 1644 KB Output is correct
10 Correct 35 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 15 ms 2412 KB Output is correct
7 Correct 13 ms 1280 KB Output is correct
8 Correct 31 ms 4332 KB Output is correct
9 Correct 9 ms 1644 KB Output is correct
10 Correct 35 ms 4972 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 19 ms 2412 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 48 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 36 ms 4716 KB Output is correct
12 Correct 41 ms 5356 KB Output is correct
13 Correct 28 ms 3308 KB Output is correct
14 Correct 34 ms 4716 KB Output is correct
15 Correct 29 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 49 ms 4076 KB Output is correct
10 Correct 38 ms 3436 KB Output is correct
11 Correct 15 ms 1516 KB Output is correct
12 Correct 17 ms 1772 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 52 ms 4076 KB Output is correct
10 Correct 39 ms 3436 KB Output is correct
11 Correct 14 ms 1516 KB Output is correct
12 Correct 17 ms 1772 KB Output is correct
13 Correct 5 ms 620 KB Output is correct
14 Correct 62 ms 4588 KB Output is correct
15 Correct 72 ms 6124 KB Output is correct
16 Correct 11 ms 1388 KB Output is correct
17 Correct 46 ms 4204 KB Output is correct
18 Correct 23 ms 2540 KB Output is correct