# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1032911 |
2024-07-24T10:44:05 Z |
vjudge1 |
Gondola (IOI14_gondola) |
C++17 |
|
37 ms |
6760 KB |
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[])
{
int ind[n+1];
for(int i=0;i<=n;i++)ind[i]=-1;
unordered_set<int>seen;
for(int i=0;i<n;i++){
if(seen.count(inputSeq[i]))return 0;
seen.insert(inputSeq[i]);
if(inputSeq[i]<=n){
ind[inputSeq[i]]=i;
}
}
int val=-1,beg;
for(int i=1;i<=n;i++){
if(ind[i]!=-1){
val=i;
beg=ind[i];
break;
}
}
if(val==-1)return 1;
for(int j=(beg+1)%n;j!=beg;j=(j+1)%n){
val++;
if(inputSeq[j]==val)continue;
if(inputSeq[j]<=n)return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int*a=gondolaSeq,*b=replacementSeq;
int ind[n+1];
for(int i=0;i<=n;i++)ind[i]=-1;
for(int i=0;i<n;i++){
if(a[i]<=n){
ind[a[i]]=i;
}
}
int val=1,beg=0;
for(int i=1;i<=n;i++){
if(ind[i]!=-1){
val=i;
beg=ind[i];
break;
}
}
int begval[n];
begval[beg]=val;
for(int j=(beg+1)%n;j!=beg;j=(j+1)%n){
val++;
if(n<val)val-=n;
begval[j]=val;
}
int place=0;
int cur=n+1;
int p[n];
for(int i=0;i<n;i++){
p[i]=i;
}
sort(p,p+n,[&](int i,int j)->bool {
return a[i]<a[j];
});
for(int i=0;i<n;i++){
int pp=p[i];
while(begval[pp]<a[pp]){
b[place++]=begval[pp];
begval[pp]=cur++;
}
}
return place;
}
//----------------------
const int mod=1e9+9;
using lint=int64_t;
int mul(lint i,lint j){
return i*j%mod;
}
int expo(int i,int j){
int ans=1;
while(j){
if(j&1){
ans=mul(ans,i);
}
i=mul(i,i);
j>>=1;
}
return ans;
}
int countReplacement(int n, int inputSeq[])
{
int*a=inputSeq;
if(!valid(n,a))return 0;
int ind[n+1];
for(int i=0;i<=n;i++)ind[i]=-1;
for(int i=0;i<n;i++){
if(a[i]<=n){
ind[a[i]]=i;
}
}
bool found=0;
int val=1,beg=0;
for(int i=1;i<=n;i++){
if(ind[i]!=-1){
found=1;
val=i;
beg=ind[i];
break;
}
}
int begval[n];
begval[beg]=val;
for(int j=(beg+1)%n;j!=beg;j=(j+1)%n){
val++;
if(n<val)val-=n;
begval[j]=val;
}
int place=0;
int cur=n+1;
int p[n];
for(int i=0;i<n;i++){
p[i]=i;
}
sort(p,p+n,[&](int i,int j)->bool {
return a[i]<a[j];
});
int ans=1;
int haveblock=n;
for(int i=0;i<n;i++){
int pp=p[i];
if(begval[pp]<a[pp]){
ans=mul(ans,expo(haveblock,a[pp]-cur));
cur=a[pp]+1;
}
haveblock--;
}
if(!found)ans=mul(ans,n);
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:130:9: warning: unused variable 'place' [-Wunused-variable]
130 | int place=0;
| ^~~~~
# |
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 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
2232 KB |
Output is correct |
7 |
Correct |
6 ms |
1368 KB |
Output is correct |
8 |
Correct |
9 ms |
3688 KB |
Output is correct |
9 |
Correct |
3 ms |
1628 KB |
Output is correct |
10 |
Correct |
13 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
2232 KB |
Output is correct |
7 |
Correct |
6 ms |
1116 KB |
Output is correct |
8 |
Correct |
9 ms |
3768 KB |
Output is correct |
9 |
Correct |
3 ms |
1628 KB |
Output is correct |
10 |
Correct |
9 ms |
4224 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
1976 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
14 ms |
5616 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 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 |
1 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 |
1 ms |
348 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 |
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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
1628 KB |
Output is correct |
12 |
Correct |
9 ms |
1628 KB |
Output is correct |
13 |
Correct |
10 ms |
1624 KB |
Output is correct |
14 |
Correct |
7 ms |
1576 KB |
Output is correct |
15 |
Correct |
11 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
19 ms |
3880 KB |
Output is correct |
10 |
Correct |
16 ms |
3436 KB |
Output is correct |
11 |
Correct |
6 ms |
1628 KB |
Output is correct |
12 |
Correct |
7 ms |
1740 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 |
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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
20 ms |
3948 KB |
Output is correct |
10 |
Correct |
16 ms |
3428 KB |
Output is correct |
11 |
Correct |
6 ms |
1624 KB |
Output is correct |
12 |
Correct |
7 ms |
1720 KB |
Output is correct |
13 |
Correct |
2 ms |
836 KB |
Output is correct |
14 |
Correct |
25 ms |
5072 KB |
Output is correct |
15 |
Correct |
37 ms |
6760 KB |
Output is correct |
16 |
Correct |
5 ms |
1372 KB |
Output is correct |
17 |
Correct |
18 ms |
4184 KB |
Output is correct |
18 |
Correct |
10 ms |
2484 KB |
Output is correct |