# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
781021 |
2023-07-12T15:51:28 Z |
vjudge1 |
Gondola (IOI14_gondola) |
C++17 |
|
16 ms |
2416 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include "gondola.h"
#define MAX 250000
#define MOD 1000000009
using namespace std;
int mark[MAX + 10];
vector <pair <int, int>> v;
int valid(int n, int inputSeq[])
{
int posOrig = -1;
for (int i = 0; i < n; i++)
{
if (mark[inputSeq[i]] == 1)
return 0;
if (inputSeq[i] <= n)
posOrig = i;
mark[inputSeq[i]] = 1;
}
if (posOrig == -1)
return 1;
int pos = posOrig;
for (int i = 1; i <= n; i++)
{
if (inputSeq[pos] <= n && (inputSeq[pos] - inputSeq[posOrig] + n) % n != (pos - posOrig + n) % n)
return 0;
pos = (pos + 1) % n;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int posOrig = -1;
for (int i = 0; i < n; i++)
if (gondolaSeq[i] <= n)
posOrig = i;
if (posOrig == -1)
for (int i = 0; i < n; i++)
v.push_back({gondolaSeq[i], i + 1});
else
{
int pos = posOrig;
int g = gondolaSeq[posOrig];
for (int i = 1; i <= n; i++)
{
if (gondolaSeq[pos] > n)
v.push_back({gondolaSeq[pos], g});
pos = (pos + 1) % n;
if (g == n - 1)
g = n;
else
g = (g + 1) % n;
}
}
sort(v.begin(), v.end());
int l = 0, nn = n + 1;
for (auto it : v)
{
replacementSeq[l] = it.second;
l++;
nn++;
while (nn <= it.first)
{
replacementSeq[l] = nn - 1;
l++;
nn++;
}
}
return l;
}
int fastPow(int base, int exp)
{
int ans = 1;
while (exp != 0)
if (exp % 2 == 0)
{
exp = exp / 2;
base = 1LL * base * base % MOD;
}
else
{
exp--;
ans = 1LL * ans * base % MOD;
}
return ans;
}
int countReplacement(int n, int inputSeq[])
{
if (valid(n, inputSeq) == 0)
return 0;
int posOrig = -1;
for (int i = 0; i < n; i++)
if (inputSeq[i] <= n)
posOrig = i;
int ans;
if (posOrig == -1)
{
ans = n;
for (int i = 0; i < n; i++)
v.push_back({inputSeq[i], i + 1});
}
else
{
ans = 1;
int pos = posOrig;
int g = inputSeq[posOrig];
for (int i = 1; i <= n; i++)
{
if (inputSeq[pos] > n)
v.push_back({inputSeq[pos], g});
pos = (pos + 1) % n;
if (g == n - 1)
g = n;
else
g = (g + 1) % n;
}
}
sort(v.begin(), v.end());
int cntGreater = v.size(), aux = n;
for (auto it : v)
{
ans = 1LL * ans * fastPow(cntGreater, it.first - aux - 1) % MOD;
cntGreater--;
aux = it.first;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
7 ms |
896 KB |
Output is correct |
8 |
Correct |
7 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
8 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
7 ms |
980 KB |
Output is correct |
8 |
Correct |
6 ms |
852 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
8 ms |
856 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
1236 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
7 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
668 KB |
Output is correct |
13 |
Correct |
11 ms |
1488 KB |
Output is correct |
14 |
Correct |
6 ms |
596 KB |
Output is correct |
15 |
Correct |
16 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
12 ms |
2416 KB |
Output is correct |
10 |
Correct |
10 ms |
2112 KB |
Output is correct |
11 |
Correct |
5 ms |
1620 KB |
Output is correct |
12 |
Correct |
5 ms |
1448 KB |
Output is correct |
13 |
Correct |
2 ms |
704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
12 ms |
2384 KB |
Output is correct |
10 |
Correct |
10 ms |
2000 KB |
Output is correct |
11 |
Correct |
4 ms |
1580 KB |
Output is correct |
12 |
Correct |
5 ms |
1472 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Runtime error |
8 ms |
1888 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |