# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
68815 |
2018-08-18T15:18:48 Z |
Vahan |
Gondola (IOI14_gondola) |
C++17 |
|
44 ms |
8168 KB |
#include "gondola.h"
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
long long x[200000],xx[200000],a[200000];
long long mod=1000000009;
vector<long long> g;
int valid(int n, int inputSeq[])
{
vector<long long> v;
for(long long i=0;i<n;i++)
xx[i]=inputSeq[i];
sort(xx,xx+n);
long long t=0;
for(long long i=1;i<n;i++)
if(xx[i]==xx[i-1])
{
t=1;
break;
}
if(t==1)
return 0;
for(long long i=0;i<n;i++)
{
if(inputSeq[i]<=n)
{
v.push_back(inputSeq[i]);
x[inputSeq[i]]=i;
}
}
t=0;
for(long long i=1;i<v.size();i++)
{
if(v[i-1]>v[i])
t++;
}
if(t>=2)
return 0;
if(t==1 && v.back()>v[0])
return 0;
t=0;
for(long long i=1;i<v.size();i++)
{
if(v[i-1]<v[i])
{
if(v[i]-v[i-1]!=x[v[i]]-x[v[i-1]])
{
t=1;
break;
}
}
else if(v[i-1]>v[i])
{
if((n-(v[i-1]-v[i]))!=x[v[i]]-x[v[i-1]])
{
t=1;
break;
}
}
}
if(t==1)
return 0;
return 1;
}
long long binpow(long long a,long long b)
{
if(b==0)
return 1;
if(b%2==0)
{
long long c=binpow(a,b/2);
return (c*c)%mod;
}
else
{
long long c=binpow(a,b/2);
return (a*((c*c)%mod))%mod;
}
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
vector<pair<int,int> >v;
for(int i=0;i<n;i++)
{
if(gondolaSeq[i]<=n)
{
a[i]=gondolaSeq[i];
for(int j=i+1;j<n;j++)
{
a[j]=a[j-1]+1;
a[j]%=n;
if(a[j]==0)
a[j]=n;
}
for(int j=i-1;j>=0;j--)
{
a[j]=a[j+1]-1;
a[j]%=n;
if(a[j]==0)
a[j]=n;
}
break;
}
}
if(a[0]==0)
for(int i=0;i<n;i++)
a[i]=i+1;
for(int i=0;i<n;i++)
if(gondolaSeq[i]>n)
v.push_back({gondolaSeq[i],i});
sort(v.begin(),v.end());
int t=0;
for(int i=0;i<v.size();i++)
{
int u;
replacementSeq[t++]=a[v[i].second];
if(i==0)
u=n+1;
else
u=v[i-1].first+1;
for(int j=u;j<v[i].first;j++)
replacementSeq[t++]=j;
}
return t;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if(valid(n,inputSeq)==0)
return 0;
for(long long i=0;i<n;i++)
{
if(inputSeq[i]>n)
g.push_back(inputSeq[i]);
}
sort(g.begin(),g.end());
long long k=g.size();
long long pat=1;
for(long long i=0;i<g.size();i++)
{
long long u;
if(i==0)
u=g[i]-n-1;
else
u=g[i]-g[i-1]-1;
pat*=binpow(k,u);
pat%=mod;
k--;
}
if(g.size()==n)
pat*=n;
pat%=mod;
return pat;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:33:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i=1;i<v.size();i++)
~^~~~~~~~~
gondola.cpp:43:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i=1;i<v.size();i++)
~^~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:116:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++)
~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:144:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i=0;i<g.size();i++)
~^~~~~~~~~
gondola.cpp:155:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(g.size()==n)
~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
568 KB |
Output is correct |
4 |
Correct |
3 ms |
568 KB |
Output is correct |
5 |
Correct |
3 ms |
568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
568 KB |
Output is correct |
2 |
Correct |
2 ms |
568 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
15 ms |
1868 KB |
Output is correct |
7 |
Correct |
22 ms |
1868 KB |
Output is correct |
8 |
Correct |
18 ms |
3156 KB |
Output is correct |
9 |
Correct |
11 ms |
3156 KB |
Output is correct |
10 |
Correct |
27 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3164 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
12 ms |
3164 KB |
Output is correct |
7 |
Correct |
23 ms |
3164 KB |
Output is correct |
8 |
Correct |
17 ms |
3164 KB |
Output is correct |
9 |
Correct |
9 ms |
3164 KB |
Output is correct |
10 |
Correct |
24 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3164 KB |
Output is correct |
13 |
Correct |
13 ms |
3164 KB |
Output is correct |
14 |
Correct |
3 ms |
3164 KB |
Output is correct |
15 |
Correct |
25 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3164 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
3 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3164 KB |
Output is correct |
2 |
Correct |
3 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
4 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
3 ms |
3164 KB |
Output is correct |
8 |
Correct |
3 ms |
3164 KB |
Output is correct |
9 |
Correct |
3 ms |
3164 KB |
Output is correct |
10 |
Correct |
4 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3164 KB |
Output is correct |
2 |
Correct |
3 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
4 ms |
3164 KB |
Output is correct |
7 |
Correct |
3 ms |
3164 KB |
Output is correct |
8 |
Correct |
4 ms |
3164 KB |
Output is correct |
9 |
Correct |
3 ms |
3164 KB |
Output is correct |
10 |
Correct |
4 ms |
3164 KB |
Output is correct |
11 |
Correct |
16 ms |
3164 KB |
Output is correct |
12 |
Correct |
22 ms |
3164 KB |
Output is correct |
13 |
Correct |
26 ms |
3248 KB |
Output is correct |
14 |
Correct |
16 ms |
3432 KB |
Output is correct |
15 |
Correct |
29 ms |
4648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4648 KB |
Output is correct |
2 |
Correct |
2 ms |
4648 KB |
Output is correct |
3 |
Correct |
3 ms |
4648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4648 KB |
Output is correct |
2 |
Correct |
2 ms |
4648 KB |
Output is correct |
3 |
Correct |
3 ms |
4648 KB |
Output is correct |
4 |
Correct |
3 ms |
4648 KB |
Output is correct |
5 |
Correct |
2 ms |
4648 KB |
Output is correct |
6 |
Correct |
3 ms |
4648 KB |
Output is correct |
7 |
Correct |
3 ms |
4648 KB |
Output is correct |
8 |
Correct |
2 ms |
4648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4648 KB |
Output is correct |
2 |
Correct |
3 ms |
4648 KB |
Output is correct |
3 |
Correct |
3 ms |
4648 KB |
Output is correct |
4 |
Correct |
2 ms |
4648 KB |
Output is correct |
5 |
Correct |
3 ms |
4648 KB |
Output is correct |
6 |
Correct |
2 ms |
4648 KB |
Output is correct |
7 |
Correct |
3 ms |
4648 KB |
Output is correct |
8 |
Correct |
2 ms |
4648 KB |
Output is correct |
9 |
Correct |
29 ms |
4664 KB |
Output is correct |
10 |
Correct |
26 ms |
4900 KB |
Output is correct |
11 |
Correct |
14 ms |
4900 KB |
Output is correct |
12 |
Correct |
18 ms |
4900 KB |
Output is correct |
13 |
Correct |
6 ms |
4900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4900 KB |
Output is correct |
2 |
Correct |
2 ms |
4900 KB |
Output is correct |
3 |
Correct |
2 ms |
4900 KB |
Output is correct |
4 |
Correct |
3 ms |
4900 KB |
Output is correct |
5 |
Correct |
3 ms |
4900 KB |
Output is correct |
6 |
Correct |
3 ms |
4900 KB |
Output is correct |
7 |
Correct |
2 ms |
4900 KB |
Output is correct |
8 |
Correct |
2 ms |
4900 KB |
Output is correct |
9 |
Correct |
41 ms |
5428 KB |
Output is correct |
10 |
Correct |
33 ms |
5792 KB |
Output is correct |
11 |
Correct |
12 ms |
5792 KB |
Output is correct |
12 |
Correct |
17 ms |
5792 KB |
Output is correct |
13 |
Correct |
6 ms |
5792 KB |
Output is correct |
14 |
Correct |
42 ms |
7088 KB |
Output is correct |
15 |
Correct |
44 ms |
8168 KB |
Output is correct |
16 |
Correct |
11 ms |
8168 KB |
Output is correct |
17 |
Correct |
38 ms |
8168 KB |
Output is correct |
18 |
Correct |
24 ms |
8168 KB |
Output is correct |