# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
418197 |
2021-06-05T08:08:40 Z |
iulia13 |
Gondola (IOI14_gondola) |
C++14 |
|
25 ms |
2328 KB |
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define ll long long
const int N = 1e5 + 5;
const int mod = 1e9 + 9;
int vc[N];
int valid(int n, int v[])
{
int poz = -1, val, i;
for (i = 0; i < n; i++)
if (v[i] <= n)
{
val = v[i];
poz = i;
break;
}
if (poz == -1)
{
sort(v, v + n);
for (i = 1; i < n; i++)
if (v[i] == v[i - 1])
return 0;
return 1;
}
for (i = poz + 1; i < n; i++)
{
if (n < v[i])
continue;
int x = val + i - poz;
if (x > n)
x -= n;
if (x != v[i])
return 0;
}
sort(v, v + n);
for (i = 1; i < n; i++)
if (v[i] == v[i - 1])
return 0;
return 1;
}
struct ura{
int orig, now;
};
ura a[N];
bool cmp(ura x, ura y)
{
return x.now < y.now;
}
int replacement(int n, int v[], int ans[])
{
int poz = -1, cnt = 0, l = 0, val, i;
for (i = 0; i < n; i++)
if (v[i] <= n)
{
val = v[i];
poz = i;
break;
}
if (poz == -1)
poz = 0, val = 1;
for (i = 0; i < n; i++)
{
if (v[i] <= n)
continue;
int x = val + i - poz;
if (x > n)
x -= n;
a[++cnt] = {x, v[i]};
}
int last = n + 1;
sort(a + 1, a + cnt + 1, cmp);
for (i = 1; i <= cnt; i++)
{
ans[l++] = a[i].orig;
while(last < a[i].now)
{
ans[l++] = last;
last++;
}
last++;
}
return l;
}
int inm (int x, int y)
{
ll p = x;
ll q = y;
return p * q % mod;
}
int rid(int b, int e)
{
int r = 1;
while(e)
{
if (e % 2)
r = inm(r, b);
b = inm(b, b);
e /= 2;
}
return r;
}
int countReplacement(int n, int v[])
{
if (!valid(n, v))
return 0;
int ok = 1, i;
for(i = 0; i < n && ok; i++)
if(v[i] <= n)
ok = 0;
sort(v, v + n);
vector <int> v2;
v2.push_back(n);
int poz = -1;
for(i = 0; i < n; i++)
if(v[i] > n)
{
if(poz == -1)
poz = n - i;
v2.push_back(v[i]);
}
int sol = 1;
for(i = 0; i < v2.size() - 1; i++)
{
sol = inm(sol, rid(poz, v2[i + 1] - v2[i] - 1));
poz--;
}
if(ok)
sol = inm(sol, n);
return sol;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:22:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
22 | if (v[i] == v[i - 1])
| ^~
gondola.cpp:24:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
24 | return 1;
| ^~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:123:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for(i = 0; i < v2.size() - 1; i++)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
600 KB |
Output is correct |
7 |
Correct |
10 ms |
912 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
17 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
520 KB |
Output is correct |
7 |
Correct |
10 ms |
844 KB |
Output is correct |
8 |
Correct |
12 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
17 ms |
912 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
5 ms |
556 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
10 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
856 KB |
Output is correct |
12 |
Correct |
11 ms |
860 KB |
Output is correct |
13 |
Correct |
16 ms |
1484 KB |
Output is correct |
14 |
Correct |
9 ms |
828 KB |
Output is correct |
15 |
Correct |
24 ms |
2328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
17 ms |
1460 KB |
Output is correct |
10 |
Correct |
15 ms |
1212 KB |
Output is correct |
11 |
Correct |
6 ms |
716 KB |
Output is correct |
12 |
Correct |
7 ms |
732 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
18 ms |
1456 KB |
Output is correct |
10 |
Correct |
15 ms |
1228 KB |
Output is correct |
11 |
Correct |
6 ms |
688 KB |
Output is correct |
12 |
Correct |
7 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
22 ms |
2084 KB |
Output is correct |
15 |
Correct |
25 ms |
2248 KB |
Output is correct |
16 |
Correct |
5 ms |
696 KB |
Output is correct |
17 |
Correct |
17 ms |
1536 KB |
Output is correct |
18 |
Correct |
9 ms |
1188 KB |
Output is correct |