#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int n,a[maxn];
bool check_valid()
{
unordered_set<int>used;
int st = -1;
for(int i = 0; i < n; i++)
{
if(used.find(a[i])!=used.end()) return false;
used.insert(a[i]);
if(1<=a[i] && a[i] <= n) st = i;
}
if(st==-1) return true;
int last = a[st];
int i = (st+1)%n;
while(i!=st)
{
last++;
if(last>n) last = 1;
if(1<=a[i] && a[i]<=n)
{
if(last!=a[i]) return false;
}
i = (i+1)%n;
}
return true;
}
int valid(int N, int inputSeq[])
{
n = N;
for(int i = 0; i < n; i++) a[i] = inputSeq[i];
return check_valid();
}
int need[maxn];
void make_need()
{
int st = -1;
for(int i = 0; i < n; i++) if(1 <= a[i] && a[i] <= n) st = i;
if(st==-1)
{
for(int i = 0; i < n; i++) need[i] = i+1;
return;
}
int last = a[st];
int i = (st+1)%n;
while(i!=st)
{
last++;
if(last>n) last = 1;
need[i] = last;
i = (i+1)%n;
}
}
vector<int> do_replace()
{
int l = 0;
for(int i = 0; i < n; i++) if(a[i]>l) l = a[i];
l = l - n;
vector<pair<int,int> >pos;
for(int i = 0; i < n; i++) if(a[i]>n) pos.push_back({a[i],need[i]});
sort(pos.begin(),pos.end());
vector<int>res;
int last = n;
for(pair<int,int> nb : pos)
{
res.push_back(nb.second);
for(int j = last+1; j < nb.first; j++) res.push_back(j);
last = nb.first;
}
return res;
}
int replacement(int N, int gondolaSeq[], int replacementSeq[])
{
n = N;
for(int i = 0; i < n; i++) a[i] = gondolaSeq[i];
make_need();
vector<int>pom = do_replace();
for(int i = 0; i < pom.size(); i++) replacementSeq[i] = pom[i];
return pom.size();
}
int countReplacement(int N, int inputSeq[])
{
n = N;
for(int i = 0; i < n; i++) a[i] = inputSeq[i];
if(!check_valid()) return 0;
///OSHTE
int maxch = 0;
for(int i = 0; i < n; i++) maxch = max(maxch,a[i]);
if(n+3!=maxch) return 1;
int ch1,ch2,br = 0;
ch1 = ch2 = 0;
for(int i = 0; i < n; i++)
{
if(a[i] > n)
{
br++;
ch1 = ch2;
ch2 = a[i];
}
}
if(ch1>ch2) swap(ch1,ch2);
if(br==2&&ch1==n+2&&ch2==n+3) return 2;
return 1;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:97:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int i = 0; i < pom.size(); i++) replacementSeq[i] = pom[i];
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
2232 KB |
Output is correct |
7 |
Correct |
6 ms |
1000 KB |
Output is correct |
8 |
Correct |
9 ms |
3692 KB |
Output is correct |
9 |
Correct |
3 ms |
1628 KB |
Output is correct |
10 |
Correct |
10 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
4 ms |
2232 KB |
Output is correct |
7 |
Correct |
6 ms |
1116 KB |
Output is correct |
8 |
Correct |
8 ms |
3692 KB |
Output is correct |
9 |
Correct |
5 ms |
1628 KB |
Output is correct |
10 |
Correct |
11 ms |
4204 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
1976 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
19 ms |
5788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 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 |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
1372 KB |
Output is correct |
12 |
Correct |
9 ms |
1368 KB |
Output is correct |
13 |
Correct |
9 ms |
1624 KB |
Output is correct |
14 |
Correct |
5 ms |
1116 KB |
Output is correct |
15 |
Correct |
13 ms |
2360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |