#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef pair<int,int> P;
const int maxN=100010;
int valid(int n, int inputSeq[]){
map<int,int> M;
int a[maxN*2],fir=-1,firN=n+1;
for (int i=0;i<n;i++){
a[n+i]=a[i]=inputSeq[i];
if (M.count(a[i]))return 0;else M[a[i]]=1;
if (1<=a[i]&&a[i]<=n)
if (firN>a[i]){firN=a[i];fir=i;}
}
if (fir==-1)return 1;
for (int i=fir+1;i<n+fir;i++)
if (1<=a[i]&&a[i]<=n){
if(a[i]-firN!=i-fir)return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
priority_queue<P,vector<P>,greater<P> >Q;
int a[maxN*2],ans[maxN*3],fir=-1,firN=n+1,Max=n;
for (int i=0;i<n;i++){
a[n+i]=a[i]=gondolaSeq[i];
if (1<=a[i]&&a[i]<=n)
if (firN>a[i]){firN=a[i];fir=i;}
if (a[i]>Max)Max=a[i];
}
if (fir==-1)Q.push(make_pair(a[n-1],1));
for (int i=fir+1;i<n+fir;i++)
if (a[i]>n){
int y=(firN+i-fir)%n;
if (y==0)y=n;
Q.push(make_pair(a[i],y));
}
int N=0,last=n;
while(!Q.empty()){
P X=Q.top();Q.pop();
int x=X.first,y=X.second;
// printf("%d %d\n",x,y);
replacementSeq[N++]=y;
for (int i=last+1;i<x;i++)
replacementSeq[N++]=i;
last=x;
}
return Max-n;
}
//----------------------
int countReplacement(int n, int inputSeq[]){
return 1;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:25:16: warning: unused variable 'ans' [-Wunused-variable]
int a[maxN*2],ans[maxN*3],fir=-1,firN=n+1,Max=n;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
19 ms |
2552 KB |
Output is correct |
7 |
Correct |
14 ms |
732 KB |
Output is correct |
8 |
Correct |
35 ms |
4572 KB |
Output is correct |
9 |
Correct |
11 ms |
1656 KB |
Output is correct |
10 |
Correct |
47 ms |
5368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
20 ms |
2552 KB |
Output is correct |
7 |
Correct |
14 ms |
760 KB |
Output is correct |
8 |
Correct |
35 ms |
4492 KB |
Output is correct |
9 |
Correct |
12 ms |
1656 KB |
Output is correct |
10 |
Correct |
47 ms |
5368 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
25 ms |
2424 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
63 ms |
5368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
380 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
13 ms |
1784 KB |
Output is correct |
12 |
Correct |
14 ms |
1912 KB |
Output is correct |
13 |
Correct |
20 ms |
1788 KB |
Output is correct |
14 |
Correct |
12 ms |
1656 KB |
Output is correct |
15 |
Correct |
25 ms |
2504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |