#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int a,k,idx,mod,B[100000],pas;
map <long long,long long> mp;
long long xarisxad(long long base,long long power) {
long long result=1;
while(power>0) {
if(power%2==1) result=(result*base)%mod;
base=(base*base)%mod;
power/=2;
}
return result;
}
int valid(int n,int A[]) {
idx=-1;
for(int i=0;i<n;i++) {
if(mp[A[i]]==1) return 0;
mp[A[i]]=1;
}
for(int i=0;i<n;i++) {
if(A[i]<=n) { idx=i; break; }
}
if(idx==-1) return 1;
a=A[idx];
for(int i=idx;i<n;i++) {
if(A[i]>n) { a++; a%=(n+1); if(a==0) a++; continue; }
if(A[i]!=a) return 0;
a++;
a%=(n+1);
if(a==0) a++;
}
for(int i=0;i<idx;i++) {
if(A[i]>n) { a++; a%=(n+1); if(a==0) a++; continue; }
if(A[i]!=a) return 0;
a++;
a%=(n+1);
if(a==0) a++;
}
return 1;
}
int replacement(int n,int A[],int ans[]) {
idx=-1;
for(int i=0;i<n;i++) {
if(A[i]<=n) { idx=i; break; }
}
a=A[idx];
for(int i=idx;i<n;i++) {
B[i]=a;
a++;
a%=(n+1);
if(a==0) a++;
}
for(int i=0;i<idx;i++) {
B[i]=a;
a++;
a%=(n+1);
if(a==0) a++;
}
vector < pair < int , int > > v;
for(int i=0;i<n;i++) {
if(A[i]>n) v.push_back({A[i],i});
}
sort(v.begin(),v.end());
k=n;
for(int i=0;i<v.size();i++) {
while(B[v[i].second]<A[v[i].second]) {
ans[pas]=B[v[i].second];
pas++;
k++;
B[v[i].second]=k;
}
}
return pas;
}
int countReplacement(int n,int A[]) {
if(valid(n, A)==0) return 0;
vector <int> v;
v.push_back(n);
for(int i=0;i<n;i++) {
if(A[i]>n) v.push_back(A[i]);
}
sort(v.begin(),v.end());
long long ans1=1;
mod=1000000009;
for(int i=0;i<v.size()-1;i++) {
ans1*=xarisxad(v.size()-i-1,v[i+1]-v[i]-1);
ans1%=mod;
}
if(v.size()==n+1) { ans1*=n; ans1%=mod; }
return ans1;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:66: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]
66 | for(int i=0;i<v.size();i++) {
| ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i=0;i<v.size()-1;i++) {
| ~^~~~~~~~~~~
gondola.cpp:90:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
90 | if(v.size()==n+1) { ans1*=n; ans1%=mod; }
| ~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
300 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 |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
15 ms |
3068 KB |
Output is correct |
7 |
Correct |
8 ms |
1072 KB |
Output is correct |
8 |
Correct |
28 ms |
5424 KB |
Output is correct |
9 |
Correct |
8 ms |
1860 KB |
Output is correct |
10 |
Correct |
34 ms |
6196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
3016 KB |
Output is correct |
7 |
Correct |
9 ms |
1160 KB |
Output is correct |
8 |
Correct |
31 ms |
5452 KB |
Output is correct |
9 |
Correct |
9 ms |
1952 KB |
Output is correct |
10 |
Correct |
39 ms |
6228 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
15 ms |
2848 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
40 ms |
6444 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 |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 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 |
308 KB |
Output is correct |
2 |
Correct |
0 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 |
300 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 |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
1372 KB |
Output is correct |
12 |
Correct |
8 ms |
1472 KB |
Output is correct |
13 |
Correct |
12 ms |
1572 KB |
Output is correct |
14 |
Correct |
12 ms |
1340 KB |
Output is correct |
15 |
Correct |
18 ms |
2372 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
216 KB |
Output is correct |
9 |
Correct |
43 ms |
5972 KB |
Output is correct |
10 |
Correct |
32 ms |
5064 KB |
Output is correct |
11 |
Correct |
11 ms |
2064 KB |
Output is correct |
12 |
Correct |
14 ms |
2504 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
216 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
40 ms |
6044 KB |
Output is correct |
10 |
Correct |
35 ms |
5060 KB |
Output is correct |
11 |
Correct |
13 ms |
2140 KB |
Output is correct |
12 |
Correct |
15 ms |
2500 KB |
Output is correct |
13 |
Correct |
3 ms |
844 KB |
Output is correct |
14 |
Correct |
47 ms |
7240 KB |
Output is correct |
15 |
Correct |
65 ms |
8248 KB |
Output is correct |
16 |
Correct |
9 ms |
1868 KB |
Output is correct |
17 |
Correct |
34 ms |
5528 KB |
Output is correct |
18 |
Correct |
20 ms |
3396 KB |
Output is correct |