#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cout << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
int valid(int n, int a[]){
int idx = -1;
vector<int> num;
for (int i = 0; i < n; i++){
if (a[i] <= n) idx = i;
num.push_back(a[i]);
}
sort(all(num));
num.resize(distance(num.begin(), unique(all(num))));
if (num.size() < n) return 0;
if (idx == -1) return 1;
vector<int> v;
idx -= (a[idx] - 1);
if (idx < 0) idx += n;
for (int i = 0; i < n; i++){
v.push_back(a[(idx+i)%n]);
}
for (int i = 0; i < n; i++){
if (v[i] <= n && v[i] != i+1) return 0;
}
return 1;
}
//----------------------
const int maxn = 3e5 + 10;
int val[maxn];
int mark[maxn];
int replacement(int n, int a[], int res[]){
memset(mark, -1, sizeof mark);
int mx = *max_element(a, a + n);
int ans = mx - n;
if (ans == 0) return ans;
int idx = min_element(a, a + n) - a;
if (a[idx] > n){
for (int i = 0; i < n; i++){
val[i] = i+1;
}
}
else{
idx -= (a[idx] - 1);
if (idx < 0) idx += n;
for (int i = 0; i < n; i++){
val[(idx+i)%n] = i+1;
}
}
set<int> st;
for (int i = 0; i < n; i++){
if (a[i] != val[i]) st.insert(i);
mark[a[i]] = i;
}
for (int i = n+1; i <= mx; i++){
if (mark[i] != -1){
res[i-n-1] = val[mark[i]];
val[mark[i]] = i;
st.erase(mark[i]);
continue;
}
int idx = *(st.begin());
res[i-n-1] = val[idx];
val[idx] = i;
}
return ans;
}
//----------------------
const int mod = 1e9 + 9;
int pwr(int a, int b){
int res = 1;
for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) res = 1ll * res * a % mod;
return res;
}
int countReplacement(int n, int a[]){
vector<int> v;
for (int i = 0; i < n; i++){
if (a[i] > n) v.push_back(a[i]);
}
sort(all(v));
int ans = 1;
int lst = n, cnt = v.size();
for (auto x: v){
ans = 1ll * ans * pwr(cnt, x - lst - 1) % mod;
lst = x;
cnt--;
}
if (v.size() == n){
ans = 1ll * ans * n % mod;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:37:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | if (num.size() < n) return 0;
| ~~~~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:118:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
118 | if (v.size() == n){
| ~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1104 KB |
Output is correct |
7 |
Correct |
13 ms |
1508 KB |
Output is correct |
8 |
Correct |
9 ms |
1868 KB |
Output is correct |
9 |
Correct |
4 ms |
728 KB |
Output is correct |
10 |
Correct |
12 ms |
1860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1128 KB |
Output is correct |
7 |
Correct |
12 ms |
1452 KB |
Output is correct |
8 |
Correct |
9 ms |
1868 KB |
Output is correct |
9 |
Correct |
4 ms |
820 KB |
Output is correct |
10 |
Correct |
13 ms |
1860 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
232 KB |
Output is correct |
13 |
Correct |
6 ms |
1104 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
13 ms |
1996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1460 KB |
Output is correct |
3 |
Correct |
1 ms |
1456 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
2 ms |
1492 KB |
Output is correct |
9 |
Correct |
2 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1464 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
2 ms |
1492 KB |
Output is correct |
11 |
Correct |
7 ms |
2156 KB |
Output is correct |
12 |
Correct |
8 ms |
2352 KB |
Output is correct |
13 |
Correct |
18 ms |
4052 KB |
Output is correct |
14 |
Correct |
6 ms |
2132 KB |
Output is correct |
15 |
Correct |
30 ms |
4192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
11 ms |
1064 KB |
Output is correct |
10 |
Correct |
9 ms |
984 KB |
Output is correct |
11 |
Correct |
4 ms |
704 KB |
Output is correct |
12 |
Correct |
5 ms |
740 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
12 ms |
1092 KB |
Output is correct |
10 |
Correct |
10 ms |
960 KB |
Output is correct |
11 |
Correct |
4 ms |
680 KB |
Output is correct |
12 |
Correct |
6 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
15 ms |
1308 KB |
Output is correct |
15 |
Correct |
17 ms |
1484 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
11 ms |
1052 KB |
Output is correct |
18 |
Correct |
6 ms |
968 KB |
Output is correct |