# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1061671 |
2024-08-16T11:37:27 Z |
Nonoze |
Gondola (IOI14_gondola) |
C++17 |
|
45 ms |
6692 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int valid(int n, int inputSeq[]) { vector<int> a;
for (int i=0; i<n; i++) a.pb(inputSeq[i]);
int first=-1;
for (int i=0; i<n; i++) if (a[i]<=n) first=i;
map<int, int> vec;
int mx=0;
for (auto &u: a) vec[u]++;
for (auto u: vec) if (u.se>1) return 0;
if (first==-1) return 0;
rotate(a.begin(), a.begin()+(first-(a[first]-1)+n)%n, a.end());
for (int i=0; i<n; i++) if (a[i]<=n && a[i]!=i+1) return 0;
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vector<int> a;
for (int i=0; i<n; i++) a.pb(gondolaSeq[i]);
int first=0;
for (int i=0; i<n; i++) if (a[i]<=n) first=i;
if (first) rotate(a.begin(), a.begin()+(first-(a[first]-1)+n)%n, a.end());
map<int, int> vec;
vector<int> ans;
int mx=*max_element(all(a));
for (int i=0; i<n; i++) vec[a[i]]=i, a[i]=i+1;
for (int i=n+1; i<=mx; i++) {
if (!vec.count(i)) ans.pb(a[vec.rbegin()->se]), a[vec.rbegin()->se]=i;
else ans.pb(a[vec[i]]), a[vec[i]]=i;
}
for (int i=0; i<sz(ans); i++) replacementSeq[i]=ans[i];
return sz(ans);
}
//----------------------
#define ll long long
const int MOD=1e9+9;
ll fastpow(int x, ll y) {
if (y==0) return 1;
ll temp=fastpow(x, y/2); temp=(temp*temp)%MOD;
if (y%2) temp*=x;
return temp%MOD;
}
int countReplacement(int n, int inputSeq[]) { vector<int> a;
for (int i=0; i<n; i++) a.pb(inputSeq[i]);
if (!valid(n, inputSeq) && *min_element(all(a))<=n) return 0;
vector<int> vec(1, n);
ll nxt=0, ans=1;
for (int i=0; i<n; i++) if (a[i]>n) nxt++, vec.pb(a[i]);
sort(all(vec));
if (sz(vec)==n+1) ans=n;
for (int i=0; i<sz(vec)-1; i++) {
ans=(ans*fastpow(sz(vec)-i-1, vec[i+1]-vec[i]-1))%MOD;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:16:6: warning: unused variable 'mx' [-Wunused-variable]
16 | int mx=0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
# |
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 |
8 ms |
2520 KB |
Output is correct |
7 |
Correct |
21 ms |
4556 KB |
Output is correct |
8 |
Correct |
22 ms |
4580 KB |
Output is correct |
9 |
Correct |
7 ms |
1592 KB |
Output is correct |
10 |
Correct |
18 ms |
5332 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 |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
2616 KB |
Output is correct |
7 |
Correct |
21 ms |
4556 KB |
Output is correct |
8 |
Correct |
14 ms |
4768 KB |
Output is correct |
9 |
Correct |
4 ms |
1628 KB |
Output is correct |
10 |
Correct |
18 ms |
5332 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
12 ms |
2384 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
29 ms |
5652 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 |
600 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 |
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 |
1 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 |
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 |
1 ms |
424 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
21 ms |
5068 KB |
Output is correct |
12 |
Correct |
28 ms |
5668 KB |
Output is correct |
13 |
Correct |
23 ms |
3284 KB |
Output is correct |
14 |
Correct |
15 ms |
5076 KB |
Output is correct |
15 |
Correct |
20 ms |
3292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
31 ms |
5208 KB |
Output is correct |
10 |
Correct |
23 ms |
4220 KB |
Output is correct |
11 |
Correct |
8 ms |
1828 KB |
Output is correct |
12 |
Correct |
14 ms |
2136 KB |
Output is correct |
13 |
Correct |
2 ms |
860 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 |
444 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
29 ms |
5072 KB |
Output is correct |
10 |
Correct |
24 ms |
4188 KB |
Output is correct |
11 |
Correct |
8 ms |
1884 KB |
Output is correct |
12 |
Correct |
11 ms |
2140 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
45 ms |
5968 KB |
Output is correct |
15 |
Correct |
42 ms |
6692 KB |
Output is correct |
16 |
Correct |
7 ms |
1628 KB |
Output is correct |
17 |
Correct |
29 ms |
4604 KB |
Output is correct |
18 |
Correct |
20 ms |
3064 KB |
Output is correct |