Submission #59261

# Submission time Handle Problem Language Result Execution time Memory
59261 2018-07-21T11:09:58 Z TadijaSebez Gondola (IOI14_gondola) C++11
100 / 100
56 ms 13196 KB
#include "gondola.h"
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
bool Check(vector<int> a)
{
	int n=a.size(),i,j,k;
	for(i=0;i<n;i++) if(a[i]<=n) break;
	if(i==n)
	{
		sort(a.begin(),a.end());
		for(i=1;i<n;i++) if(a[i]==a[i-1]) return 0;
		return 1;
	}
	vector<int> b;
	j=i-a[i]+1;
	if(j<0)
	{
		for(k=j+n;k<n;k++) b.pb(a[k]);
		for(k=0;k<j+n;k++) b.pb(a[k]);
	}
	else
	{
		for(k=j;k<n;k++) b.pb(a[k]);
		for(k=0;k<j;k++) b.pb(a[k]);
	}
	//for(i=0;i<n;i++) printf("%i ",b[i]);printf("\n");
	for(i=0;i<n;i++) if(b[i]<=n && b[i]!=i+1) return 0;
	for(i=0;i<n;i++) if(b[i]==0) return 0;
	sort(b.begin(),b.end());
	for(i=1;i<n;i++) if(b[i]==b[i-1]) return 0;
	return 1;
}
vector<int> Replace(vector<int> a)
{
	int n=a.size(),i,j,k;vector<int> sol;
	for(i=0;i<n;i++) if(a[i]<=n) break;
	if(i==n)
	{
		vector<pair<int,int> > tmp;
		for(i=0;i<n;i++) tmp.pb(mp(a[i],i+1));
		sort(tmp.begin(),tmp.end());
		int m=n;
		for(i=0;i<tmp.size();i++)
		{
			sol.pb(tmp[i].second);m++;
			while(m<tmp[i].first)
			{
				sol.pb(m);m++;
			}
		}
		return sol;
	}
	vector<int> b;
	j=i-a[i]+1;
	if(j<0)
	{
		for(k=j+n;k<n;k++) b.pb(a[k]);
		for(k=0;k<j+n;k++) b.pb(a[k]);
	}
	else
	{
		for(k=j;k<n;k++) b.pb(a[k]);
		for(k=0;k<j;k++) b.pb(a[k]);
	}
	vector<pair<int,int> > tmp;
	int m=n;
	for(i=0;i<n;i++) if(b[i]>n) tmp.pb(mp(b[i],i+1));
	sort(tmp.begin(),tmp.end());
	for(i=0;i<tmp.size();i++)
	{
		sol.pb(tmp[i].second);m++;
		while(m<tmp[i].first)
		{
			sol.pb(m);m++;
		}
	}
	return sol;
}
const int mod=1e9+9;
int pow(int x, int k)
{
	int ret=1;
	for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;
	return ret;
}
int Count(vector<int> a)
{
	vector<int> tmp;
	int i,j,k,n=a.size();
	for(i=0;i<n;i++) if(a[i]>n) tmp.pb(a[i]);
	sort(tmp.begin(),tmp.end());
	int last=n,sol=1,sz=tmp.size();
	for(i=0;i<sz;i++)
	{
		int dist=tmp[i]-last-1;
		sol=(ll)sol*pow(sz-i,dist)%mod;
		last=tmp[i];
	}
	if(sz==n) sol=(ll)sol*n%mod;
	return sol;
}
int valid(int n, int a[])
{
	int i;
	vector<int> b;
	for(i=0;i<n;i++) b.pb(a[i]);
	return (int)Check(b);
}
int replacement(int n, int a[], int sol[])
{
	int i;
	vector<int> b;
	for(i=0;i<n;i++) b.pb(a[i]);
	vector<int> ans=Replace(b);
	for(i=0;i<ans.size();i++) sol[i]=ans[i];
	return ans.size();
}
int countReplacement(int n, int a[])
{
	int i;
	vector<int> b;
	for(i=0;i<n;i++) b.pb(a[i]);
	if(Check(b)) return Count(b);
	else return 0;
}

Compilation message

gondola.cpp: In function 'std::vector<int> Replace(std::vector<int>)':
gondola.cpp:48:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=0;i<tmp.size();i++)
           ~^~~~~~~~~~~
gondola.cpp:74:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<tmp.size();i++)
          ~^~~~~~~~~~~
gondola.cpp: In function 'int Count(std::vector<int>)':
gondola.cpp:94:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j,k,n=a.size();
        ^
gondola.cpp:94:10: warning: unused variable 'k' [-Wunused-variable]
  int i,j,k,n=a.size();
          ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:120:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<ans.size();i++) sol[i]=ans[i];
          ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 14 ms 1700 KB Output is correct
7 Correct 19 ms 3108 KB Output is correct
8 Correct 25 ms 3256 KB Output is correct
9 Correct 9 ms 3256 KB Output is correct
10 Correct 18 ms 4032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4032 KB Output is correct
2 Correct 2 ms 4032 KB Output is correct
3 Correct 2 ms 4032 KB Output is correct
4 Correct 2 ms 4032 KB Output is correct
5 Correct 2 ms 4032 KB Output is correct
6 Correct 10 ms 4032 KB Output is correct
7 Correct 26 ms 4876 KB Output is correct
8 Correct 22 ms 4992 KB Output is correct
9 Correct 10 ms 4992 KB Output is correct
10 Correct 25 ms 5776 KB Output is correct
11 Correct 3 ms 5776 KB Output is correct
12 Correct 2 ms 5776 KB Output is correct
13 Correct 12 ms 5776 KB Output is correct
14 Correct 2 ms 5776 KB Output is correct
15 Correct 22 ms 6516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6516 KB Output is correct
2 Correct 2 ms 6516 KB Output is correct
3 Correct 3 ms 6516 KB Output is correct
4 Correct 3 ms 6516 KB Output is correct
5 Correct 2 ms 6516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6516 KB Output is correct
2 Correct 2 ms 6516 KB Output is correct
3 Correct 2 ms 6516 KB Output is correct
4 Correct 3 ms 6516 KB Output is correct
5 Correct 2 ms 6516 KB Output is correct
6 Correct 3 ms 6516 KB Output is correct
7 Correct 2 ms 6516 KB Output is correct
8 Correct 3 ms 6516 KB Output is correct
9 Correct 3 ms 6516 KB Output is correct
10 Correct 3 ms 6516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6516 KB Output is correct
2 Correct 3 ms 6516 KB Output is correct
3 Correct 3 ms 6516 KB Output is correct
4 Correct 2 ms 6516 KB Output is correct
5 Correct 2 ms 6516 KB Output is correct
6 Correct 2 ms 6516 KB Output is correct
7 Correct 3 ms 6516 KB Output is correct
8 Correct 4 ms 6516 KB Output is correct
9 Correct 3 ms 6516 KB Output is correct
10 Correct 4 ms 6516 KB Output is correct
11 Correct 26 ms 7112 KB Output is correct
12 Correct 24 ms 7780 KB Output is correct
13 Correct 19 ms 7780 KB Output is correct
14 Correct 21 ms 8300 KB Output is correct
15 Correct 40 ms 8592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8592 KB Output is correct
2 Correct 2 ms 8592 KB Output is correct
3 Correct 2 ms 8592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8592 KB Output is correct
2 Correct 3 ms 8592 KB Output is correct
3 Correct 4 ms 8592 KB Output is correct
4 Correct 3 ms 8592 KB Output is correct
5 Correct 3 ms 8592 KB Output is correct
6 Correct 2 ms 8592 KB Output is correct
7 Correct 3 ms 8592 KB Output is correct
8 Correct 3 ms 8592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8592 KB Output is correct
2 Correct 3 ms 8592 KB Output is correct
3 Correct 3 ms 8592 KB Output is correct
4 Correct 3 ms 8592 KB Output is correct
5 Correct 2 ms 8592 KB Output is correct
6 Correct 3 ms 8592 KB Output is correct
7 Correct 2 ms 8592 KB Output is correct
8 Correct 2 ms 8592 KB Output is correct
9 Correct 28 ms 8848 KB Output is correct
10 Correct 33 ms 8848 KB Output is correct
11 Correct 14 ms 8848 KB Output is correct
12 Correct 16 ms 8848 KB Output is correct
13 Correct 5 ms 8848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8848 KB Output is correct
2 Correct 3 ms 8848 KB Output is correct
3 Correct 2 ms 8848 KB Output is correct
4 Correct 3 ms 8848 KB Output is correct
5 Correct 3 ms 8848 KB Output is correct
6 Correct 3 ms 8848 KB Output is correct
7 Correct 3 ms 8848 KB Output is correct
8 Correct 3 ms 8848 KB Output is correct
9 Correct 28 ms 10104 KB Output is correct
10 Correct 24 ms 10104 KB Output is correct
11 Correct 10 ms 10104 KB Output is correct
12 Correct 17 ms 10104 KB Output is correct
13 Correct 6 ms 10104 KB Output is correct
14 Correct 56 ms 11916 KB Output is correct
15 Correct 40 ms 13168 KB Output is correct
16 Correct 12 ms 13168 KB Output is correct
17 Correct 33 ms 13196 KB Output is correct
18 Correct 17 ms 13196 KB Output is correct