#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define P push
typedef long long ll;
int valid(int n, int inputSeq[]){
int arr[n];
for(int i=0;i<n;i++){
if(inputSeq[i]<=n){
int pp=inputSeq[i]-i-1+n;
for(int j=0;j<n;j++){
arr[(pp+j)%n]=inputSeq[j];
}
break;
}
}
for(int i=0;i<n;i++)if(arr[i]<=n && arr[i]-1!=i)return 0;
sort(arr,arr+n);
for(int i=1;i<n;i++)if(arr[i]==arr[i-1])return 0;
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int arr[n];
for(int i=0;i<n;i++)arr[i]=gondolaSeq[i];
for(int i=0;i<n;i++){
if(gondolaSeq[i]<=n){
int pp=gondolaSeq[i]-i-1+n;
for(int j=0;j<n;j++){
arr[(pp+j)%n]=gondolaSeq[j];
}
break;
}
}
int cur=n+1;
int pos=0;
vector<pair<int,int> > v;
for(int i=0;i<n;i++)v.PB(MP(arr[i],i+1));
sort(v.begin(),v.end());
for(int i=0;i<n;i++){
if(v[i].F<=n)continue;
replacementSeq[pos]=v[i].S;pos++;
for(cur;cur<v[i].F;cur++){replacementSeq[pos]=cur;pos++;}
cur++;
}
return pos;
}
//----------------------
bool visited[200];
int ans=0;
int mx=0;
void dfs(int n,int x,vector<pair<int,int> > v,int cur){
if(x==v[cur].S){
if(cur==v.size()-1){
bool all=true;
for(int i=1;i<=mx;i++)if(!visited[i])all=false;
if(all)ans++;
return;
}
visited[v[cur+1].F]=true;
dfs(n,v[cur+1].F,v,cur+1);
visited[v[cur+1].F]=false;
}
else{
for(int i=max(x,n)+1;i<=v[cur].S;i++){
bool ok=true;
for(int j=0;j<v.size();j++)if(j!=cur && i==v[j].S)ok=false;
if(!ok || visited[i])continue;
visited[i]=true;
dfs(n,i,v,cur);
visited[i]=false;
}
}
}
int countReplacement(int n, int inputSeq[]){
int arr[n];
for(int i=0;i<n;i++){
if(inputSeq[i]<=n){
int pp=inputSeq[i]-i-1+n;
for(int j=0;j<n;j++){
arr[(pp+j)%n]=inputSeq[j];
}
break;
}
}
vector<pair<int,int> > v;
memset(visited,false,sizeof(visited));
for(int i=0;i<n;i++){
if(arr[i]>n){v.PB(MP(i+1,arr[i]));mx=max(mx,arr[i]);}
else visited[arr[i]]=true;
}
if(v.size()==0)return 1;
visited[v[0].F]=true;
dfs(n,v[0].F,v,0);
return ans;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:50:9: warning: statement has no effect [-Wunused-value]
50 | for(cur;cur<v[i].F;cur++){replacementSeq[pos]=cur;pos++;}
| ^~~
gondola.cpp: In function 'void dfs(int, int, std::vector<std::pair<int, int> >, int)':
gondola.cpp:62:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | if(cur==v.size()-1){
| ~~~^~~~~~~~~~~~
gondola.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int j=0;j<v.size();j++)if(j!=cur && i==v[j].S)ok=false;
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
6 ms |
552 KB |
Output is correct |
7 |
Correct |
12 ms |
972 KB |
Output is correct |
8 |
Correct |
11 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
472 KB |
Output is correct |
10 |
Correct |
13 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
6 ms |
588 KB |
Output is correct |
7 |
Correct |
12 ms |
880 KB |
Output is correct |
8 |
Correct |
11 ms |
784 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
13 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
5 ms |
552 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
12 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
18 ms |
1988 KB |
Output is correct |
12 |
Correct |
16 ms |
2140 KB |
Output is correct |
13 |
Correct |
18 ms |
1348 KB |
Output is correct |
14 |
Correct |
19 ms |
2064 KB |
Output is correct |
15 |
Correct |
23 ms |
2244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Execution timed out |
1080 ms |
204 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Execution timed out |
1083 ms |
204 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Execution timed out |
1074 ms |
204 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |