#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int valid(int n, int inputSeq[])
{
vector <pair <int, int> > v;
for(int i = 0; i < n; i ++)
if(inputSeq[i] <= n)
v.push_back({inputSeq[i], i + 1});
sort(v.begin(), v.end());
for(int i = 1; i < v.size(); i ++){
int ab = v[i].first - v[i - 1].first, ds;
if(v[i].second > v[i - 1].second){
ds = v[i].second - v[i - 1].second;
} else {
ds = v[i].second + (n - v[i - 1].second);
}
if(ds != ab) return 0;
}
sort(inputSeq, inputSeq + n);
for(int i = 1; i < n; i ++){
if(inputSeq[i] == inputSeq[i - 1]) return 0;
}
return 1;
}
//----------------------
int used[N];
int replacement(int n, int gondolaSeq[], int rp[])
{
int pos = 1, mx = 0, sz = 0, id = 0;
vector <int> v, nm(n);
vector < pair <int, int> > d;
for(int i = 0; i < n; i ++){
mx = max(mx, gondolaSeq[i]);
used[gondolaSeq[i]] = 1;
if(gondolaSeq[i] > n){
d.push_back({gondolaSeq[i], i});
}
else
pos = gondolaSeq[i], id = i;
}
for(int i = n + 1; i <= mx; i ++){
if(!used[i])
v.push_back(i);
}
for(int i = 0; i < n; i ++){
nm[id] = pos;
pos ++;
id ++;
if(pos > n) pos = 1;
if(id >= n) id = 0;
}
sort(d.begin(), d.end());
int cur = n + 1;
for(int i = 0; i < d.size(); i ++){
int ps = nm[d[i].second];
rp[sz ++] = ps;
while(cur < d[i].first){
if(!used[cur])
rp[sz ++] = cur;
cur ++;
}
}
return sz;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
vector <pair <int, int> > v;
for(int i = 0; i < n; i ++)
if(inputSeq[i] <= n)
v.push_back({inputSeq[i], i + 1});
sort(v.begin(), v.end());
for(int i = 1; i < v.size(); i ++){
int ab = v[i].first - v[i - 1].first, ds;
if(v[i].second > v[i - 1].second){
ds = v[i].second - v[i - 1].second;
} else {
ds = v[i].second + (n - v[i - 1].second);
}
if(ds != ab) return 0;
}
sort(inputSeq, inputSeq + n);
for(int i = 1; i < n; i ++){
if(inputSeq[i] == inputSeq[i - 1]) return 0;
}
memset(used, 0, sizeof(used));
long long ans = 1, cnt = 0, mx = 0, mod = 1e9 + 7;
for(int i = 0; i < n; i ++){
used[ inputSeq[i] ] = 1;
if(inputSeq[i] > n) cnt ++;
if(mx < inputSeq[i]) mx = inputSeq[i];
}
if(cnt == n) ans = n;
for(int i = n + 1; i < mx; i ++){
if(used[ inputSeq[i] ]){
cnt --;
continue;
}
ans = (ans * cnt) % mod;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:14:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < v.size(); i ++){
~~^~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:61:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < d.size(); i ++){
~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:82:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < v.size(); i ++){
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
624 KB |
Output is correct |
2 |
Correct |
3 ms |
624 KB |
Output is correct |
3 |
Correct |
2 ms |
624 KB |
Output is correct |
4 |
Correct |
2 ms |
624 KB |
Output is correct |
5 |
Correct |
3 ms |
624 KB |
Output is correct |
6 |
Correct |
18 ms |
1380 KB |
Output is correct |
7 |
Correct |
36 ms |
1996 KB |
Output is correct |
8 |
Correct |
25 ms |
2124 KB |
Output is correct |
9 |
Correct |
15 ms |
2124 KB |
Output is correct |
10 |
Correct |
39 ms |
2148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2148 KB |
Output is correct |
2 |
Correct |
3 ms |
2148 KB |
Output is correct |
3 |
Correct |
3 ms |
2148 KB |
Output is correct |
4 |
Correct |
2 ms |
2148 KB |
Output is correct |
5 |
Correct |
3 ms |
2148 KB |
Output is correct |
6 |
Correct |
21 ms |
2148 KB |
Output is correct |
7 |
Correct |
33 ms |
2148 KB |
Output is correct |
8 |
Correct |
25 ms |
2148 KB |
Output is correct |
9 |
Correct |
14 ms |
2148 KB |
Output is correct |
10 |
Correct |
34 ms |
2148 KB |
Output is correct |
11 |
Correct |
3 ms |
2148 KB |
Output is correct |
12 |
Correct |
2 ms |
2148 KB |
Output is correct |
13 |
Correct |
13 ms |
2148 KB |
Output is correct |
14 |
Correct |
3 ms |
2148 KB |
Output is correct |
15 |
Correct |
34 ms |
2148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2148 KB |
Output is correct |
2 |
Correct |
3 ms |
2148 KB |
Output is correct |
3 |
Correct |
3 ms |
2148 KB |
Output is correct |
4 |
Correct |
3 ms |
2148 KB |
Output is correct |
5 |
Correct |
3 ms |
2148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2148 KB |
Output is correct |
2 |
Correct |
2 ms |
2148 KB |
Output is correct |
3 |
Correct |
2 ms |
2148 KB |
Output is correct |
4 |
Correct |
3 ms |
2148 KB |
Output is correct |
5 |
Correct |
3 ms |
2148 KB |
Output is correct |
6 |
Correct |
3 ms |
2148 KB |
Output is correct |
7 |
Correct |
3 ms |
2148 KB |
Output is correct |
8 |
Correct |
4 ms |
2148 KB |
Output is correct |
9 |
Correct |
3 ms |
2148 KB |
Output is correct |
10 |
Correct |
2 ms |
2148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2148 KB |
Output is correct |
2 |
Correct |
2 ms |
2148 KB |
Output is correct |
3 |
Correct |
2 ms |
2148 KB |
Output is correct |
4 |
Correct |
3 ms |
2148 KB |
Output is correct |
5 |
Correct |
3 ms |
2148 KB |
Output is correct |
6 |
Correct |
2 ms |
2148 KB |
Output is correct |
7 |
Correct |
3 ms |
2148 KB |
Output is correct |
8 |
Correct |
2 ms |
2148 KB |
Output is correct |
9 |
Correct |
3 ms |
2148 KB |
Output is correct |
10 |
Correct |
3 ms |
2148 KB |
Output is correct |
11 |
Correct |
19 ms |
2148 KB |
Output is correct |
12 |
Correct |
18 ms |
2148 KB |
Output is correct |
13 |
Correct |
29 ms |
2148 KB |
Output is correct |
14 |
Correct |
15 ms |
2148 KB |
Output is correct |
15 |
Correct |
31 ms |
3104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
3104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |