#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define pi pair<int,int>
#define f first
#define s second
using ll = long long;
const int inf=1e9;
const int mod=1e9+9;
int replacement(int n, int a[], int r[]) {
int m=inf;
forn(i,n) m=min(m,a[i]);
if (m>n) {
vector<int> p;
set<int> s;
forn(i,n) s.insert(i);
map<int,int> mp;
forn(i,n) mp[a[i]]=i;
int l=0; forn(i,n) l=max(l,a[i]);
vector<int> v(n); forn(i,n) v[i]=i+1;
for (int i=n+1; i<=l; ++i) {
if (mp.count(i)) {
p.pb(v[mp[i]]);
s.erase(mp[i]);
} else {
p.pb(v[*s.begin()]);
v[*s.begin()]=i;
}
}
forn(i,p.size()) r[i]=p[i];
return p.size();
}
vector<int> p;
set<int> s;
forn(i,n) if (a[i]>n) s.insert(i);
map<int,int> mp;
forn(i,n) mp[a[i]]=i;
int l=0; forn(i,n) l=max(l,a[i]);
int z=-1;
forn(i,n) if (a[i]<=n) z=i;
vector<int> v(n);
if (z==-1) forn(i,n) v[i]=i+1;
else forn(i,n) v[i]=((a[z]-1+i-z+n)%n)+1;
for (int i=n+1; i<=l; ++i) {
if (mp.count(i)) {
p.pb(v[mp[i]]);
s.erase(mp[i]);
} else {
p.pb(v[*s.begin()]);
v[*s.begin()]=i;
}
}
forn(i,p.size()) r[i]=p[i];
return p.size();
}
int countReplacement(int n, int a[]) {
#define int ll
set<int> s;
forn(i,n) s.insert(a[i]);
if (s.size()<n) return 0;
int m=inf;
forn(i,n) m=min(m,1ll*a[i]);
if (m>n) {
vector<int> v; forn(i,n) v.pb(a[i]);
sort(all(v));
ll ans=1;
int p=0;
int k=n;
for (int i=n+1; i<=v.back(); ++i) {
if (v[p]==i) {
--k; ++p; continue;
}
ans=(1ll*ans*k)%mod;
}
ans=(ans*n)%mod;
//forn(i,n) ans=(ans*(i+1))%mod;
return ans;
}
int i=0;
for(;i<n;++i) if (a[i]<=n) break;
i-=a[i]-1;
if (i<0) i+=n;
vector<int> v;
int z=1;
for (int j=i; j<i+n; ++j) {
if (a[j%n]<=n) z&=a[j%n]==j-i+1;
else v.pb(a[j%n]);
}
if (!z) return 0;
if (!v.size()) return 1;
sort(all(v));
int k=v.size();
ll ans=1;
int p=0;
for (int i=n+1; i<=v.back(); ++i) {
if (v[p]==i) {
--k; ++p; continue;
}
ans=(1ll*ans*k)%mod;
}
return ans;
#undef int
}
int valid(int n, int a[]) {
return !!countReplacement(n,a);
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forn(i,n) for(int i=0;i<n;++i)
......
34 | forn(i,p.size()) r[i]=p[i];
| ~~~~~~~~~~
gondola.cpp:34:5: note: in expansion of macro 'forn'
34 | forn(i,p.size()) r[i]=p[i];
| ^~~~
gondola.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forn(i,n) for(int i=0;i<n;++i)
......
58 | forn(i,p.size()) r[i]=p[i];
| ~~~~~~~~~~
gondola.cpp:58:3: note: in expansion of macro 'forn'
58 | forn(i,p.size()) r[i]=p[i];
| ^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:66:15: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | if (s.size()<n) return 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
2224 KB |
Output is correct |
7 |
Correct |
28 ms |
3568 KB |
Output is correct |
8 |
Correct |
15 ms |
3852 KB |
Output is correct |
9 |
Correct |
5 ms |
1364 KB |
Output is correct |
10 |
Correct |
19 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
2132 KB |
Output is correct |
7 |
Correct |
20 ms |
3668 KB |
Output is correct |
8 |
Correct |
15 ms |
3872 KB |
Output is correct |
9 |
Correct |
7 ms |
1364 KB |
Output is correct |
10 |
Correct |
19 ms |
4436 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
276 KB |
Output is correct |
13 |
Correct |
10 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
24 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
26 ms |
4632 KB |
Output is correct |
12 |
Correct |
20 ms |
5204 KB |
Output is correct |
13 |
Correct |
32 ms |
4272 KB |
Output is correct |
14 |
Correct |
19 ms |
4512 KB |
Output is correct |
15 |
Correct |
29 ms |
3868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
31 ms |
4688 KB |
Output is correct |
10 |
Correct |
30 ms |
4072 KB |
Output is correct |
11 |
Correct |
10 ms |
1752 KB |
Output is correct |
12 |
Correct |
12 ms |
2004 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
38 ms |
4644 KB |
Output is correct |
10 |
Correct |
28 ms |
4092 KB |
Output is correct |
11 |
Correct |
11 ms |
1752 KB |
Output is correct |
12 |
Correct |
10 ms |
2112 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
14 |
Execution timed out |
1080 ms |
6472 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |