# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
599468 |
2022-07-19T14:23:30 Z |
AriaH |
Gondola (IOI14_gondola) |
C++17 |
|
72 ms |
10072 KB |
#include "gondola.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define Mp make_pair
#define endl "\n"
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 9;
const ll inf = 8e18;
ll pw(ll a, ll b)
{
if(a == 0) return 0;
ll ret = 1;
while(b)
{
if(b & 1)
{
ret = ret * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return ret;
}
map < int, int > mark;
int valid(int n, int inputSeq[])
{
int id = -1;
for(int i = 0; i < n; i ++)
{
if(++ mark[inputSeq[i]] > 1) return 0;
if(inputSeq[i] <= n)
{
id = i;
}
}
if(id == -1) return 1;
int start = (id - (inputSeq[id] - 1) + n + n) % n;
for(int i = 0; i < n; i ++)
{
int j = (i + start) % n;
if(inputSeq[j] > n) continue;
if(inputSeq[j] != i + 1)
{
return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int A[], int replacementSeq[])
{
int Mx = 0;
int id = -1;
for(int i = 0; i < n; i ++)
{
Mx = max(Mx, A[i]);
mark[A[i]] ++;
if(A[i] <= n)
{
id = i;
}
}
vector < int > vec;
vec.push_back(Mx);
for(int i = Mx - 1; i > n; i --)
{
if(mark[i] > 2) return -1;
if(mark[i] == 0) vec.push_back(i);
}
int start;
if(id == -1) { start = 0; }
else { start = (id - (A[id] - 1) + n + n) % n; }
for(int i = 0; i < n; i ++)
{
int j = (start + i) % n;
if(A[j] <= n) continue;
///printf("i = %d j = %d\n", i, j);
if(A[j] != Mx) replacementSeq[A[j] - n - 1] = i + 1;
else
{
///printf("here i = %d j = %d\n", i, j);
int last = i + 1;
while(SZ(vec))
{
int l = vec.back();
///printf("here l = %d last = %d\n", l, last);
vec.pop_back();
replacementSeq[l - n - 1] = last;
last = l;
}
}
}
return Mx - n;
}
//----------------------
int countReplacement(int n, int A[])
{
ll ret = 1;
int id = -1;
vector < int > vec;
for(int i = 0; i < n; i ++)
{
mark[A[i]] ++;
if(mark[A[i]] > 1) return 0;
if(A[i] <= n)
{
id = i;
}
else
{
vec.push_back(A[i]);
}
}
vec.push_back(n);
sort(all(vec), greater < int > ());
for(int i = 1; i < SZ(vec); i ++)
{
ret = ret * pw(i, vec[i - 1] - vec[i] - 1) % mod;
}
int start;
if(id == -1)
{
ret = ret * n % mod;
return ret;
}
else { start = (id - (A[id] - 1) + n + n) % n; }
for(int i = 0; i < n; i ++)
{
int j = (start + i) % n;
if(A[j] > n) continue;
if(A[j] != i + 1) return 0;
}
return ret;
}
# |
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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
2132 KB |
Output is correct |
7 |
Correct |
7 ms |
596 KB |
Output is correct |
8 |
Correct |
17 ms |
3872 KB |
Output is correct |
9 |
Correct |
6 ms |
1364 KB |
Output is correct |
10 |
Correct |
21 ms |
4448 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 |
9 ms |
2132 KB |
Output is correct |
7 |
Correct |
8 ms |
596 KB |
Output is correct |
8 |
Correct |
24 ms |
3828 KB |
Output is correct |
9 |
Correct |
7 ms |
1364 KB |
Output is correct |
10 |
Correct |
23 ms |
4452 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
13 ms |
2028 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
29 ms |
4672 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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
596 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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
20 ms |
4324 KB |
Output is correct |
12 |
Correct |
29 ms |
4864 KB |
Output is correct |
13 |
Correct |
35 ms |
4644 KB |
Output is correct |
14 |
Correct |
19 ms |
4248 KB |
Output is correct |
15 |
Correct |
57 ms |
10072 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 |
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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
39 ms |
4144 KB |
Output is correct |
10 |
Correct |
30 ms |
3516 KB |
Output is correct |
11 |
Correct |
12 ms |
1504 KB |
Output is correct |
12 |
Correct |
18 ms |
1760 KB |
Output is correct |
13 |
Correct |
3 ms |
596 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 |
40 ms |
4204 KB |
Output is correct |
10 |
Correct |
30 ms |
3504 KB |
Output is correct |
11 |
Correct |
12 ms |
1516 KB |
Output is correct |
12 |
Correct |
14 ms |
1700 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
52 ms |
4836 KB |
Output is correct |
15 |
Correct |
72 ms |
6368 KB |
Output is correct |
16 |
Correct |
8 ms |
1448 KB |
Output is correct |
17 |
Correct |
34 ms |
4360 KB |
Output is correct |
18 |
Correct |
18 ms |
2600 KB |
Output is correct |