#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
map<int, int> freq;
int nseq[2*MAXN];
typedef long long ll;
const ll MOD = 1e9 + 9;
int valid(int n, int inputSeq[])
{
// int ult = 0;
for(int i = 0; i < n; i++){
nseq[i+1] = nseq[i+n+1] = inputSeq[i];
freq[inputSeq[i]]++;
if(freq[inputSeq[i]] == 2) return 0;
}
int ini = 0, auxi = n + 1;
for(int i = 1; i <= n; i++){
if(nseq[i] <= n && nseq[i] < auxi) ini = i, auxi = nseq[i];
// printf("%d %d\n", nseq[i], auxi);
}
//printf("\n");
//printf("%d\n",ini);
if(!ini) return 1;
int ult = auxi, ultaux = ini;
for(int i = ini+1; i < ini + n; i++){
if(nseq[i] <= n){
// printf("%d %d\n", nseq[i], ult );
if(nseq[i] <= ult ||nseq[i] - ult != i - ultaux) return 0;
ult = nseq[i];
ultaux = i;
}
}
return 1;
}
//----------------------
set<pair<int, int> > s;
vector<int> v;
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
for(int i = 0; i < n; i++){
nseq[i+1] = nseq[i+n+1] = gondolaSeq[i];
freq[gondolaSeq[i]]++;
}
int ini = 0, auxi = n + 1;
for(int i = 1; i <= n; i++){
if(nseq[i] <= n && nseq[i] < auxi) ini = i, auxi = nseq[i];
//printf("%d ", nseq[i]);
}
ini = (ini - auxi + 1 > 0) ? ini-auxi+1 : n + ini -auxi + 1;
//printf("\n");
if(ini == 0) ini = 1, auxi = 1;
for(int i = ini; i <= ini + n - 1; i++){
//printf("%d %d\n", i, nseq[i]);
if(nseq[i] <= n) continue;
s.insert({nseq[i],i-ini+1});
//printf("aaan");
}
int act = n;
while(!s.empty()){
set <pair<int, int> > :: iterator it = s.begin();
v.push_back(it->second);
int f = (*s.begin()).first;
int sec = (*s.begin()).second;
s.erase({f,sec});
act++;
if(f == act) continue;
s.insert({f,act});
}
for(int i = 0; i < v.size(); i++) replacementSeq[i] = v[i];
return v.size();
}
ll fexp(ll b, ll e){
if(e == 0) return 1;
if(e == 1) return b;
ll aux = fexp(b, e/2);
aux*=aux;
aux%=MOD;
if(e%2) aux *= b;
aux %= MOD;
return aux;
}
//----------------------
//map<int, int> suf;
int countReplacement(int n, int inputSeq[])
{
if(!valid(n, inputSeq)) return 0;
for(int i = 1; i <= n; i++){
s.insert({nseq[i],i-1});
//printf("%d ", nseq[i]);
}
bool flag = true;
ll ans = 1;
ll big = n;
bool ok = 1;
int act = n + 1;
while(!s.empty()){
pair<int,int> p = *(s.begin());
if(p.first <= n){
ok = false;
big--;
s.erase(s.begin());
continue;
}
ll aux = p.first - act;
ans *= fexp(big, aux);
ans %= MOD;
act = p.first + 1;
big--;
s.erase(s.begin());
}
if(ok) ans *= n, ans %= MOD;
return ans;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0; i < v.size(); i++) replacementSeq[i] = v[i];
| ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:107:7: warning: unused variable 'flag' [-Wunused-variable]
107 | bool flag = true;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
308 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 |
14 ms |
2632 KB |
Output is correct |
7 |
Correct |
13 ms |
1100 KB |
Output is correct |
8 |
Correct |
36 ms |
4812 KB |
Output is correct |
9 |
Correct |
11 ms |
1716 KB |
Output is correct |
10 |
Correct |
34 ms |
5548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
308 KB |
Output is correct |
6 |
Correct |
21 ms |
2648 KB |
Output is correct |
7 |
Correct |
11 ms |
1100 KB |
Output is correct |
8 |
Correct |
29 ms |
4872 KB |
Output is correct |
9 |
Correct |
9 ms |
1776 KB |
Output is correct |
10 |
Correct |
34 ms |
5564 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
19 ms |
2508 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
46 ms |
5828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
408 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
308 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
31 ms |
5300 KB |
Output is correct |
12 |
Correct |
30 ms |
6080 KB |
Output is correct |
13 |
Correct |
40 ms |
4996 KB |
Output is correct |
14 |
Correct |
26 ms |
5252 KB |
Output is correct |
15 |
Correct |
49 ms |
4704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
220 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 |
204 KB |
Output is correct |
9 |
Correct |
76 ms |
8520 KB |
Output is correct |
10 |
Correct |
56 ms |
7036 KB |
Output is correct |
11 |
Correct |
19 ms |
2764 KB |
Output is correct |
12 |
Correct |
23 ms |
3360 KB |
Output is correct |
13 |
Correct |
6 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
204 KB |
Output is correct |
9 |
Correct |
83 ms |
8524 KB |
Output is correct |
10 |
Correct |
56 ms |
7116 KB |
Output is correct |
11 |
Correct |
18 ms |
2768 KB |
Output is correct |
12 |
Correct |
24 ms |
3368 KB |
Output is correct |
13 |
Correct |
5 ms |
972 KB |
Output is correct |
14 |
Correct |
82 ms |
9840 KB |
Output is correct |
15 |
Correct |
101 ms |
11252 KB |
Output is correct |
16 |
Correct |
19 ms |
2336 KB |
Output is correct |
17 |
Correct |
61 ms |
7620 KB |
Output is correct |
18 |
Correct |
31 ms |
4380 KB |
Output is correct |