#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define sz(x) (ll)x.size()
#define ins insert
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
//subtask 1 & 2 & 3
int valid(int n, int arr[]){
ll p = 0;
set <ll> st; st.ins(arr[0]);
for (ll i=1; i<n; i++){
if (arr[p] > arr[i]) p = i;
if (st.find(arr[i]) == st.end()){
st.ins(arr[i]);
}
else{
return 0;
}
}
if (arr[p] > n) return 1;
vi v;
for (ll i = p; i<n; i++){
if (arr[i] <= n) v.pb(arr[i]);
else v.pb(v.back()+1);
}
for (ll i =0; i<p; i++){
if (arr[i] <= n) v.pb(arr[i]);
else v.pb(v.back()+1);
}
for (ll i =1; i<n; i++){
if (v[i] != v[i-1] + 1){
return 0;
}
}
return 1;
}
//----------------------
//subtask 4,5,6
inline void add_to_ans(ll x, ll &ans_size, int ans[]){
ans[ans_size] = x;
ans_size++;
}
int replacement(int n, int arr[], int ans[])
{
ll ans_size = 0;
vii misplaced_sorted;
ll firstIdx = 0;
for (ll i=0; i<n; i++){
if (arr[i] <= n){
firstIdx = ((i - (arr[i] - 1)) + n) % n;
}
else{
// dbg2(arr[i],i);
misplaced_sorted.pb(ii(arr[i], i));
}
}
sort(misplaced_sorted.begin(), misplaced_sorted.end());
vi rel_idx(n);
ll c = 1;
for (ll i =firstIdx; i<n; i++){
rel_idx[i] = c;
c++;
}
for (ll i =0; i<firstIdx; i++){
rel_idx[i] = c;
c++;
}
// dbg(firstIdx);
// printVct(rel_idx);
ll prev = n;
for (ll i =0; i<sz(misplaced_sorted); i++){
// dbg3(i, misplaced_sorted[i].F, misplaced_sorted[i].S);
add_to_ans(rel_idx[misplaced_sorted[i].S], ans_size, ans);
for (ll j = prev+1; j<misplaced_sorted[i].F; j++){
add_to_ans(j, ans_size, ans);
}
prev = misplaced_sorted[i].F;
}
// cout<<"ans: ";
// for (ll i=0; i<ans_size; i++){
// cout<<ans[i]<<" ";
// }
// cout<<endl;
return ans_size;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
/*
1
5
1 2 3 4 5
6
5
3 6 7 9 33
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
2776 KB |
Output is correct |
7 |
Correct |
5 ms |
604 KB |
Output is correct |
8 |
Correct |
15 ms |
5160 KB |
Output is correct |
9 |
Correct |
6 ms |
1880 KB |
Output is correct |
10 |
Correct |
21 ms |
5712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
2772 KB |
Output is correct |
7 |
Correct |
4 ms |
604 KB |
Output is correct |
8 |
Correct |
18 ms |
5116 KB |
Output is correct |
9 |
Correct |
5 ms |
1884 KB |
Output is correct |
10 |
Correct |
21 ms |
5848 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
2728 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
27 ms |
5836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
472 KB |
Output is correct |
11 |
Correct |
5 ms |
1588 KB |
Output is correct |
12 |
Correct |
5 ms |
1784 KB |
Output is correct |
13 |
Correct |
8 ms |
1748 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
13 ms |
2504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |