#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define pii pair<int,int>
int valid(int n, int inputSeq[]){
set<int> s(inputSeq,inputSeq+n);
if ((int)s.size()<n)return 0;
pii mn={n+1,-1};
for (int i = 0; i<n; i++){
if (inputSeq[i]<mn.first)mn={inputSeq[i],i};
}
int cur=mn.first;
for (int i = mn.second+1; i<n; i++){
if (inputSeq[i]<=n && inputSeq[i]!=++cur)return 0;
}
for (int i = 0; ++cur<=n; i++){
if (inputSeq[i]<=n && inputSeq[i]!=cur)return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int st=0;
for (int i = 0; i<n; i++){
if (gondolaSeq[i]<=n){
st=(i-gondolaSeq[i]+1+n)%n;
break;
}
}
vector<int> kol(n);
for (int i = st; i<n+st; i++)kol[i-st]=gondolaSeq[i%n];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int mx=0;
int l=0;
for (int i = 0; i<n; i++){
if (kol[i]>n)pq.push({kol[i],i+1});
mx=max(mx,kol[i]);
}
while(pq.size()){
pii now=pq.top();
pq.pop();
replacementSeq[l++]=now.second;
if (pq.empty())break;
if (pq.top().first>now.first+1)pq.push({now.first+1,now.first});
}
return l;
}
int countReplacement(int n, int inputSeq[]){
if (!valid(n,inputSeq))return 0;
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 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 |
1 ms |
348 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 |
1 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 |
6 ms |
2392 KB |
Output is correct |
7 |
Correct |
22 ms |
4256 KB |
Output is correct |
8 |
Correct |
13 ms |
4444 KB |
Output is correct |
9 |
Correct |
4 ms |
1628 KB |
Output is correct |
10 |
Correct |
12 ms |
4956 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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
2396 KB |
Output is correct |
7 |
Correct |
20 ms |
4092 KB |
Output is correct |
8 |
Correct |
13 ms |
4444 KB |
Output is correct |
9 |
Correct |
3 ms |
1628 KB |
Output is correct |
10 |
Correct |
12 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
9 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
24 ms |
5216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
448 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
1 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |