#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
const int mod = 1e9+9;
typedef long long ll;
typedef pair<int, int> pii;
int valid(int n, int inputSeq[])
{
int g[n+1];
bool mark[250050];
int first = -1;
for (int i = 0; i < n; i++)
{
g[i] = inputSeq[i];
if (mark[g[i]]) return 0;
mark[g[i]] = 1;
if (g[i] <= n && first == -1) first = i;
}
int cur = g[first];
for (int i = first+1; i < n; i++)
{
cur = (cur == n ? 1 : cur+1);
if (g[i] <= n && g[i] != cur) return 0;
}
for (int i = 0; i < first; i++)
{
cur = (cur == n ? 1 : cur+1);
if (g[i] <= n && g[i] != cur) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int g[n+1], ind[n+1];
int first = -1;
for (int i = 0; i < n; i++)
{
g[i] = gondolaSeq[i];
if (g[i] <= n && first == -1) first = i;
}
if (first == -1)
{
for (int i = 0; i < n; i++)
ind[i] = i+1;
}
else
{
int cur = g[first];
for (int i = first+1; i < n; i++)
{
cur = (cur == n ? 1 : cur+1);
ind[i] = cur;
}
for (int i = 0; i < first; i++)
{
cur = (cur == n ? 1 : cur+1);
ind[i] = cur;
}
}
int l = 0;
priority_queue<pii, vector<pii>, greater<pii> > pq;
for (int i = 0; i < n; i++) if (g[i] > n) pq.push({g[i], i});
int cur = n+1;
while (!pq.empty())
{
int v = pq.top().first, i = pq.top().second;
pq.pop();
replacementSeq[l++] = ind[i];
while (cur < v)
replacementSeq[l++] = cur++;
cur++;
}
return l;
}
//----------------------
ll pot(ll a, ll b)
{
if (!b) return 1ll;
ll t = pot(a, b/2);
if (b%2 == 0) return (t*t)%mod;
return (a*((t*t)%mod))%mod;
}
int countReplacement(int n, int inputSeq[])
{
if (!valid(n, inputSeq)) return 0;
int last = n+1, less;
ll ans = 1ll;
bool dif = 0;
sort(inputSeq, inputSeq+n);
int pos = n+1;
for (int i = 0; i < n; i++)
{
if (inputSeq[i] > n && pos == n+1) pos = i;
else if (inputSeq[i] <= n) dif = 1;
}
less = n-pos;
for (int i = pos; i < n; i++)
{
int v = inputSeq[i];
ans = (ans*pot(1ll*less, 1ll*(v-last)))%mod;
last = v+1, less--;
}
if (!dif)
{
ans = (ans*1ll*n)%mod;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:16: warning: 'mark[<unknown>]' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (mark[g[i]]) return 0;
~~~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
300 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
356 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
640 KB |
Output is correct |
7 |
Correct |
16 ms |
768 KB |
Output is correct |
8 |
Correct |
14 ms |
1024 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
12 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
640 KB |
Output is correct |
7 |
Correct |
12 ms |
768 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
15 ms |
1060 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
896 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
14 ms |
1148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
12 ms |
1408 KB |
Output is correct |
13 |
Correct |
17 ms |
1552 KB |
Output is correct |
14 |
Correct |
11 ms |
1280 KB |
Output is correct |
15 |
Correct |
31 ms |
2408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
25 ms |
1152 KB |
Output is correct |
10 |
Correct |
17 ms |
996 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
684 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
19 ms |
1024 KB |
Output is correct |
10 |
Correct |
18 ms |
1024 KB |
Output is correct |
11 |
Correct |
11 ms |
776 KB |
Output is correct |
12 |
Correct |
12 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Runtime error |
17 ms |
1152 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |