#include "gondola.h"
#include <vector>
#include <set>
#include <algorithm>
#include <stdio.h>
#define MOD 1000000009LL
int Vis[250005];
int valid(int n, int inputSeq[])
{
int i, r = -1;
for (i = 0; i < n; i++)
{
if (Vis[inputSeq[i]])
return 0;
Vis[inputSeq[i]] = 1;
if (inputSeq[i] <= n)
{
if (r == -1)
r = (inputSeq[i] + n - (i + 1))%n;
else if ((inputSeq[i] + n - (i + 1))%n != r)
return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int i, r = -1;
for (i = 0; i < n; i++)
{
if (gondolaSeq[i] <= n)
{
if (r == -1)
{
r = (gondolaSeq[i] + n - (i + 1))%n;
break;
}
}
}
if (r == -1)
r = 0;
std::vector<std::pair<int, int> > V;
for (i = 0; i < n; i++)
{
if (gondolaSeq[i] > n)
{
V.push_back({gondolaSeq[i], i});
gondolaSeq[i] = (i + r)%n + 1;
}
}
if (V.size() == 0)
return 0;
std::sort(V.begin(), V.end());
r = 0;
int j = 0;
for (i = n + 1; i <= V.back().first; i++)
{
replacementSeq[r] = gondolaSeq[V[j].second];
gondolaSeq[V[j].second] = i;
if (V[j].first == i)
j++;
r++;
}
return r;
}
//----------------------
long long pow(long long b, int e)
{
// printf("pow %lld %d\n", b, e);
if (e == 0)
return 1LL;
else if (e == 1)
return b;
else
{
long long r = pow(b, e/2);
r = (r*r)%MOD;
if (e%2)
r = (r*b)%MOD;
return r;
}
}
int countReplacement(int n, int inputSeq[])
{
int i, r = -1;
std::set<int> S;
for (i = 0; i < n; i++)
{
// printf("i%d\n", i);
if (S.find(inputSeq[i]) != S.end())
return 0;
S.insert(inputSeq[i]);
if (inputSeq[i] <= n)
{
if (r == -1)
r = (inputSeq[i] + n - (i + 1))%n;
else if ((inputSeq[i] + n - (i + 1))%n != r)
return 0;
}
}
// printf("r%d\n", r);
std::vector<std::pair<int, int> > V;
for (i = 0; i < n; i++)
{
if (inputSeq[i] > n)
{
V.push_back({inputSeq[i], i});
inputSeq[i] = (i + r)%n + 1;
}
}
// printf("%d\n", V.size());
if (V.size() == 0)
return 1;
std::sort(V.begin(), V.end());
long long ans = 1LL;
int j;
for (j = 0; j < V.size(); j++)
{
if (j == 0)
ans = (ans*pow(V.size() - j, V[j].first - n - 1))%MOD;
else
ans = (ans*pow(V.size() - j, V[j].first - V[j - 1].first - 1))%MOD;
}
return (int) ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:121:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < V.size(); j++)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
564 KB |
Output is correct |
4 |
Correct |
2 ms |
564 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
564 KB |
Output is correct |
2 |
Correct |
2 ms |
564 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
7 ms |
980 KB |
Output is correct |
7 |
Correct |
19 ms |
996 KB |
Output is correct |
8 |
Correct |
13 ms |
1248 KB |
Output is correct |
9 |
Correct |
8 ms |
1248 KB |
Output is correct |
10 |
Correct |
21 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1248 KB |
Output is correct |
2 |
Correct |
2 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
2 ms |
1248 KB |
Output is correct |
5 |
Correct |
2 ms |
1248 KB |
Output is correct |
6 |
Correct |
6 ms |
1248 KB |
Output is correct |
7 |
Correct |
16 ms |
1248 KB |
Output is correct |
8 |
Correct |
11 ms |
1248 KB |
Output is correct |
9 |
Correct |
5 ms |
1248 KB |
Output is correct |
10 |
Correct |
12 ms |
1248 KB |
Output is correct |
11 |
Correct |
2 ms |
1248 KB |
Output is correct |
12 |
Correct |
2 ms |
1248 KB |
Output is correct |
13 |
Correct |
14 ms |
1248 KB |
Output is correct |
14 |
Correct |
2 ms |
1248 KB |
Output is correct |
15 |
Correct |
13 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1248 KB |
Output is correct |
2 |
Correct |
2 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
2 ms |
1248 KB |
Output is correct |
5 |
Correct |
2 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1248 KB |
Output is correct |
2 |
Correct |
2 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
2 ms |
1248 KB |
Output is correct |
5 |
Correct |
2 ms |
1248 KB |
Output is correct |
6 |
Correct |
2 ms |
1248 KB |
Output is correct |
7 |
Correct |
2 ms |
1248 KB |
Output is correct |
8 |
Correct |
2 ms |
1248 KB |
Output is correct |
9 |
Correct |
2 ms |
1248 KB |
Output is correct |
10 |
Correct |
2 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1248 KB |
Output is correct |
2 |
Correct |
2 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
2 ms |
1248 KB |
Output is correct |
5 |
Correct |
2 ms |
1248 KB |
Output is correct |
6 |
Correct |
2 ms |
1248 KB |
Output is correct |
7 |
Correct |
2 ms |
1248 KB |
Output is correct |
8 |
Correct |
2 ms |
1248 KB |
Output is correct |
9 |
Correct |
2 ms |
1248 KB |
Output is correct |
10 |
Correct |
2 ms |
1248 KB |
Output is correct |
11 |
Correct |
22 ms |
1248 KB |
Output is correct |
12 |
Correct |
12 ms |
1248 KB |
Output is correct |
13 |
Correct |
28 ms |
1704 KB |
Output is correct |
14 |
Correct |
15 ms |
1704 KB |
Output is correct |
15 |
Correct |
23 ms |
2560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2560 KB |
Output is correct |
2 |
Correct |
2 ms |
2560 KB |
Output is correct |
3 |
Correct |
2 ms |
2560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2560 KB |
Output is correct |
2 |
Correct |
2 ms |
2560 KB |
Output is correct |
3 |
Correct |
2 ms |
2560 KB |
Output is correct |
4 |
Correct |
2 ms |
2560 KB |
Output is correct |
5 |
Correct |
2 ms |
2560 KB |
Output is correct |
6 |
Correct |
2 ms |
2560 KB |
Output is correct |
7 |
Correct |
2 ms |
2560 KB |
Output is correct |
8 |
Correct |
2 ms |
2560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2560 KB |
Output is correct |
2 |
Correct |
2 ms |
2560 KB |
Output is correct |
3 |
Correct |
2 ms |
2560 KB |
Output is correct |
4 |
Correct |
2 ms |
2560 KB |
Output is correct |
5 |
Correct |
2 ms |
2560 KB |
Output is correct |
6 |
Correct |
2 ms |
2560 KB |
Output is correct |
7 |
Correct |
2 ms |
2560 KB |
Output is correct |
8 |
Correct |
2 ms |
2560 KB |
Output is correct |
9 |
Correct |
60 ms |
5048 KB |
Output is correct |
10 |
Correct |
48 ms |
5048 KB |
Output is correct |
11 |
Correct |
21 ms |
5048 KB |
Output is correct |
12 |
Correct |
25 ms |
5048 KB |
Output is correct |
13 |
Incorrect |
6 ms |
5048 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5048 KB |
Output is correct |
2 |
Correct |
2 ms |
5048 KB |
Output is correct |
3 |
Correct |
2 ms |
5048 KB |
Output is correct |
4 |
Correct |
2 ms |
5048 KB |
Output is correct |
5 |
Correct |
2 ms |
5048 KB |
Output is correct |
6 |
Correct |
2 ms |
5048 KB |
Output is correct |
7 |
Correct |
2 ms |
5048 KB |
Output is correct |
8 |
Correct |
2 ms |
5048 KB |
Output is correct |
9 |
Correct |
65 ms |
5048 KB |
Output is correct |
10 |
Correct |
48 ms |
5048 KB |
Output is correct |
11 |
Correct |
18 ms |
5048 KB |
Output is correct |
12 |
Correct |
22 ms |
5048 KB |
Output is correct |
13 |
Incorrect |
6 ms |
5048 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |