#include <iostream>
#include <bits/stdc++.h>
#define mod 1000000009
#include "gondola.h"
using namespace std;
set<int> gond;
set<int> pok;
long long step(int a,int b)
{
if(b==0)
return 1;
if(b==1)
return a%mod;
if(b%2==0)
return (step(a,b/2)%mod)*(step(a,b/2)%mod);
return (step(a,b/2)%mod)*(step(a,b/2)%mod)*(a%mod);
}
int valid(int n,int seq[])
{
int prvi=-1;
for(int i=0;i<n;i++)
{
if(seq[i]<=n)
{
prvi=i;
break;
}
}
if(prvi==-1)
{
for(int i=0;i<n;i++)
{
if(gond.find(seq[i])!=gond.end())
{
return 0;
}
gond.insert(seq[i]);
}
return 1;
}
int tren=seq[prvi];
for(int i=prvi+1;i<n;i++)
{
if(tren==n)
{
if(seq[i]!=1)
{
if(seq[i]<=n)
{
return 0;
}
if(gond.find(seq[i])!=gond.end())
{
return 0;
}
gond.insert(seq[i]);
}
tren=1;
}
else if(seq[i]!=tren+1)
{
if(seq[i]<=n)
{
return 0;
}
if(gond.find(seq[i])!=gond.end())
{
return 0;
}
gond.insert(seq[i]);
tren=tren+1;
}
else{
tren=tren+1;
}
}
for(int i=0;i<=prvi;i++)
{
if(tren==n)
{
if(seq[i]!=1)
{
if(seq[i]<=n)
{
return 0;
}
if(gond.find(seq[i])!=gond.end())
{
return 0;
}
gond.insert(seq[i]);
}
tren=1;
}
else if(seq[i]!=tren+1)
{
if(seq[i]<=n)
{
return 0;
}
if(gond.find(seq[i])!=gond.end())
{
return 0;
}
gond.insert(seq[i]);
tren=tren+1;
}
else{
tren=tren+1;
}
}
return 1;
}
int replacement(int n, int gondola[], int promena[])
{
int prvi=-1;
vector <pair<int,int>> v;
for(int i=0;i<n;i++)
{
if(gondola[i]<=n)
{
prvi=i;
break;
}
}
if(prvi==-1)
{
for(int i=0;i<n;i++)
{
v.push_back({gondola[i],i+1});
}
sort(v.begin(),v.end());
int tren=n+1;
int poz=0;
for(int i=0;i<v.size();i++)
{
promena[poz]=v[i].second;
poz++;
while(tren!=v[i].first)
{
promena[poz]=tren;
poz++;
tren++;
}
tren++;
}
return poz;
}
int next;
if(gondola[prvi]==n)
{
next=1;
}
else{
next=gondola[prvi]+1;
}
for(int i=prvi+1;i<n;i++)
{
if(gondola[i]!=next)
{
v.push_back({gondola[i],next});
}
if(next==n)
{
next=1;
}
else{
next++;
}
}
for(int i=0;i<prvi;i++)
{
if(gondola[i]!=next)
{
v.push_back({gondola[i],next});
}
if(next==n)
{
next=1;
}
else{
next++;
}
}
sort(v.begin(),v.end());
int tren=n+1;
int poz=0;
for(int i=0;i<v.size();i++)
{
promena[poz]=v[i].second;
poz++;
while(tren!=v[i].first)
{
promena[poz]=tren;
poz++;
tren++;
}
tren++;
}
return poz;
}
int countReplacement(int n, int seq[])
{
if(!valid(n,seq))
return 0;
int brpok=0;
int maks=0;
for(int i=0;i<n;i++)
{
if(seq[i]>n)
{
brpok++;
pok.insert(seq[i]);
}
maks=max(maks,seq[i]);
}
if(brpok==0)
return 1;
int stepen=0;
int ans=1;
for(int i=n+1;i<=maks;i++)
{
if(pok.find(i)!=pok.end())
{
ans=(ans%mod)*(step(brpok,stepen)%mod);
brpok--;
stepen=0;
}
else{
stepen++;
}
}
return ans;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:135:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
gondola.cpp:188: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]
188 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
13 ms |
640 KB |
Output is correct |
8 |
Correct |
10 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
16 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
12 ms |
640 KB |
Output is correct |
8 |
Correct |
10 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
644 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
13 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
640 KB |
Output is correct |
12 |
Correct |
14 ms |
640 KB |
Output is correct |
13 |
Correct |
17 ms |
1296 KB |
Output is correct |
14 |
Correct |
10 ms |
640 KB |
Output is correct |
15 |
Correct |
24 ms |
2296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Incorrect |
71 ms |
6264 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Incorrect |
67 ms |
6392 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |