#include <bits/stdc++.h>
#include <gondola.h>
using namespace std;
int valid(int n, int a[])
{
map<int,int> mp;
int index=-1;
for(int i=0; i<n; ++i)
{
if(mp.count(a[i]))
return 0;
++mp[a[i]];
}
for(int i=0; i<n; ++i)
if(a[i]<=n)
{
index=i;
break;
}
if(index==-1)
return 1;
int cur=a[index];
cur=cur==n?1:cur+1;
for(int j=(index+1)%n; j!=index; j=(j+1)%n,cur=cur==n?1:cur+1)
if(a[j]<=n && a[j] !=cur)
return 0;
return 1;
}
int replacement(int n, int a[], int ans[])
{
vector<int> real(n);
int index=-1, sol=0, cur;
for(int i=0; i<n; ++i)
if(a[i]<=n)
{
real[i]=a[i];
index=i;
break;
}
if(index==-1){
real[0]=1;
index=0;
}
cur=real[index];
cur=cur==n?1:cur+1;
for(int j=(index+1)%n; j!=index; j=(j+1)%n,cur=cur==n?1:cur+1)
real[j]=cur;
vector<pair<int,int>> b;
for(int i=0; i<n; ++i)
if(a[i]>n)
b.emplace_back(a[i],i);
sort(b.begin(),b.end());
int last=n;
for(auto [val,idx]:b)
{
ans[sol++]=real[idx];
for(int i=last+1; i<val; ++i)
ans[sol++]=i;
last=val;
}
return sol;
}
int countReplacement(int n, int a[])
{
if(!valid(n,a))
return 0;
const int mod = 1e9+9;
vector<int> real(n);
int index=-1, cur, sol=1;
for(int i=0; i<n; ++i)
if(a[i]<=n)
{
real[i]=a[i];
index=i;
break;
}
if(index==-1){
real[0]=1;
sol = n;
index=0;
}
cur=real[index];
cur=cur==n?1:cur+1;
for(int j=(index+1)%n; j!=index; j=(j+1)%n,cur=cur==n?1:cur+1)
real[j]=cur;
vector<pair<int,int>> b;
for(int i=0; i<n; ++i)
if(a[i]>n)
b.emplace_back(a[i],i);
sort(b.begin(),b.end());
int last=n, cnt=b.size();
auto pow=[&](int b, int e){
if(e<1)
return 1;
int ans =1;
while(e){
if(e&1)
ans=1LL*ans*b%mod;
b=1LL*b*b%mod, e>>=1;
}
return ans;
};
for(auto [val,idx]:b)
{
sol=(1LL*sol*pow(cnt,val-1-last))%mod;
last=val;
}
return sol;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:58:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
58 | for(auto [val,idx]:b)
| ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:108:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
108 | for(auto [val,idx]:b)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
12 ms |
2380 KB |
Output is correct |
7 |
Correct |
16 ms |
1072 KB |
Output is correct |
8 |
Correct |
25 ms |
4192 KB |
Output is correct |
9 |
Correct |
7 ms |
1500 KB |
Output is correct |
10 |
Correct |
29 ms |
4932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
2392 KB |
Output is correct |
7 |
Correct |
11 ms |
992 KB |
Output is correct |
8 |
Correct |
42 ms |
4276 KB |
Output is correct |
9 |
Correct |
10 ms |
1484 KB |
Output is correct |
10 |
Correct |
33 ms |
4880 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
23 ms |
2244 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
40 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
1356 KB |
Output is correct |
12 |
Correct |
10 ms |
1484 KB |
Output is correct |
13 |
Correct |
21 ms |
1336 KB |
Output is correct |
14 |
Correct |
15 ms |
1228 KB |
Output is correct |
15 |
Correct |
23 ms |
2416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |