# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1019301 |
2024-07-10T17:09:08 Z |
presko |
Gondola (IOI14_gondola) |
C++14 |
|
18 ms |
2520 KB |
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include "gondola.h"
#define MAXN 300010
#define MOD 1000000009
using namespace std;
bool used[MAXN];
int valid(int n, int inputSeq[])
{
for(int i=0;i<n;i++)
{
if(used[inputSeq[i]])return 0;
used[inputSeq[i]]=1;
if(inputSeq[i]<=n)
{
int prev=i-1,valp=inputSeq[i]-1;
if(prev<0)prev=n-1;
if(valp<1)valp=n;
int next=i+1,valn=inputSeq[i]+1;
if(next>=n)next=0;
if(valn>n)valn=1;
if(inputSeq[prev]<=n && inputSeq[prev]!=valp)return 0;
if(inputSeq[next]<=n && inputSeq[next]!=valn)return 0;
}
}
return 1;
}
//----------------------
vector<pair<int,int>> order;
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
order.clear();
int ans=0,pos=-1;
for(int i=0;i<n;i++)if(gondolaSeq[i]<=n){pos=i;break;}
if(pos==-1)for(int i=0;i<n;i++)order.push_back({gondolaSeq[i],i+1});
else
{
int curr=gondolaSeq[pos];
for(int i=pos-1;i>=0;i--)
{
curr--;
if(curr==0)curr=n;
if(gondolaSeq[i]>n)order.push_back({gondolaSeq[i],curr});
gondolaSeq[i]=curr;
}
for(int i=n-1;i>pos;i--)
{
curr--;
if(curr==0)curr=n;
if(gondolaSeq[i]>n)order.push_back({gondolaSeq[i],curr});
gondolaSeq[i]=curr;
}
}
sort(order.begin(),order.end());
int last=n;
for(int i=0;i<order.size();i++)
{
int ind=order[i].first;
int frst=order[i].second;
replacementSeq[ans++]=frst;
for(int j=last+2;j<=ind;j++)
{
replacementSeq[ans++]=j-1;
}
last=ind;
}
return ans;
}
//----------------------
unsigned long long power(unsigned long long x, long long n)
{
if(n==0)return 1;
if(n==1)return x;
unsigned long long half=power(x,n/2);
unsigned long long ne=(half*half)%MOD;
if(n&1){ne*=x;ne%=MOD;}
return ne%MOD;
}
int countReplacement(int n, int inputSeq[])
{
order.clear();
if(!valid(n,inputSeq))return 0;
int pos=-1;
for(int i=0;i<n;i++)if(inputSeq[i]<=n){pos=i;break;}
if(pos==-1)for(int i=0;i<n;i++)order.push_back({inputSeq[i],i+1});
else
{
int curr=inputSeq[pos];
for(int i=pos-1;i>=0;i--)
{
curr--;
if(curr==0)curr=n;
if(inputSeq[i]>n)order.push_back({inputSeq[i],curr});
inputSeq[i]=curr;
}
for(int i=n-1;i>pos;i--)
{
curr--;
if(curr==0)curr=n;
if(inputSeq[i]>n)order.push_back({inputSeq[i],curr});
inputSeq[i]=curr;
}
}
if(order.size()==0)return 1;
sort(order.begin(),order.end());
unsigned long long ans=1;
if(pos==-1)ans=n;
long long last=n;
for(int i=0;i<order.size();i++)
{
long long ind=order[i].first;
int frst=order[i].second;
unsigned long long use=power(order.size()-i,ind-last-1)%MOD;
ans*=use;
ans%=MOD;
last=ind;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:62:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<order.size();i++)
| ~^~~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:119:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | for(int i=0;i<order.size();i++)
| ~^~~~~~~~~~~~~
gondola.cpp:122:13: warning: unused variable 'frst' [-Wunused-variable]
122 | int frst=order[i].second;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
12 ms |
604 KB |
Output is correct |
8 |
Correct |
5 ms |
580 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
8 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
9 ms |
576 KB |
Output is correct |
8 |
Correct |
6 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
6 ms |
608 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
9 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
604 KB |
Output is correct |
12 |
Correct |
11 ms |
604 KB |
Output is correct |
13 |
Correct |
15 ms |
1496 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
13 ms |
2520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
18 ms |
1496 KB |
Output is correct |
10 |
Correct |
9 ms |
1240 KB |
Output is correct |
11 |
Correct |
4 ms |
1116 KB |
Output is correct |
12 |
Correct |
6 ms |
984 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
1496 KB |
Output is correct |
10 |
Correct |
9 ms |
1236 KB |
Output is correct |
11 |
Correct |
5 ms |
1112 KB |
Output is correct |
12 |
Correct |
5 ms |
984 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Runtime error |
8 ms |
1116 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |