# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
422264 |
2021-06-10T00:01:04 Z |
Ozy |
Gondola (IOI14_gondola) |
C++17 |
|
40 ms |
7588 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl
#define v first
#define pos second
#define MAX 1000000009
vector<pair<lli, lli>> arr;
unordered_map<lli,lli> mapa;
lli val,ult,a,res,libres;
int valid(int n, int inputSeq[])
{
ult = -1;
val = -1;
bool res,iguales = false;
rep(i,0,n-1) {
if (inputSeq[i] <= n) {
ult = i;
val = inputSeq[i];
}
if (mapa[inputSeq[i]] == 1) {iguales = true; break;}
else mapa[inputSeq[i]] = 1;
}
if (iguales) return 0;
if (ult == -1) return 1;
val -= ult;
if(val < 1) val += n;
res = true;
rep(i,0,n-1) {
if (inputSeq[i] <= n){
if (inputSeq[i] != val) {res = false; break;}
}
val++;
if (val > n) val = 1;
}
return res;
}
lli valEn (lli p, lli n) {
lli b;
if (p < ult) {
b = val - (ult-p);
if (b < 1) b += n;
}
else {
b = val + (p-ult);
if (b > n) b -= n;
}
return b;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
val = -1;
ult = -1;
res = 0;
rep(i,0,n-1) {
if (gondolaSeq[i] <= n) {
ult = i;
val = gondolaSeq[i];
}
else arr.push_back({gondolaSeq[i],i});
a = gondolaSeq[i];
res = max(res,a);
}
sort(arr.begin(), arr.end());
if (val == -1) {
ult = 0;
val = 1;
}
lli pas = n;
lli cont = 0;
for (auto act : arr) {
a = valEn(act.pos,n);
rep(i,pas+1,act.v){
replacementSeq[cont] = a;
a = i;
cont++;
}
pas = act.v;
}
res -= n;
return res;
}
lli expo(lli num, lli e) {
lli r = 1;
while (e > 0) {
if (e&1) {
r *= num;
r %= MAX;
}
num *= num;
num %= MAX;
e /= 2;
}
return r;
}
int countReplacement(int n, int inputSeq[])
{
bool iguales = false;
val = -1;
ult = -1;
res = 0;
libres = n;
rep(i,0,n-1) {
if (inputSeq[i] <= n) {
if (ult == -1) {
ult = i;
val = inputSeq[i];
}
else {
a = valEn(i,n);
if (a != inputSeq[i]) return 0;
}
libres--;
}
else arr.push_back({inputSeq[i],i});
if (mapa[inputSeq[i]] == 1) {iguales = true; break;}
else mapa[inputSeq[i]] = 1;
}
if (iguales) return 0;
sort(arr.begin(), arr.end());
if (val == -1) {
res = n;
val = 1;
ult = 0;
}
else res = 1;
lli pas = n;
for (auto act : arr) {
a = act.v - pas - 1;
a = expo(libres,a);
res *= a;
res %= MAX;
libres--;
pas = act.v;
}
return res;
}
# |
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 |
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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
1960 KB |
Output is correct |
7 |
Correct |
12 ms |
660 KB |
Output is correct |
8 |
Correct |
15 ms |
3456 KB |
Output is correct |
9 |
Correct |
5 ms |
1484 KB |
Output is correct |
10 |
Correct |
18 ms |
3904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
1872 KB |
Output is correct |
7 |
Correct |
10 ms |
568 KB |
Output is correct |
8 |
Correct |
19 ms |
3436 KB |
Output is correct |
9 |
Correct |
6 ms |
1484 KB |
Output is correct |
10 |
Correct |
17 ms |
3804 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
13 ms |
1776 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
27 ms |
5224 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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 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 |
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 |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 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 |
11 |
Correct |
9 ms |
608 KB |
Output is correct |
12 |
Correct |
14 ms |
640 KB |
Output is correct |
13 |
Correct |
16 ms |
1732 KB |
Output is correct |
14 |
Correct |
9 ms |
600 KB |
Output is correct |
15 |
Correct |
23 ms |
2436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 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 |
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 |
26 ms |
4848 KB |
Output is correct |
10 |
Correct |
21 ms |
4200 KB |
Output is correct |
11 |
Correct |
9 ms |
1948 KB |
Output is correct |
12 |
Correct |
11 ms |
2188 KB |
Output is correct |
13 |
Correct |
3 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
204 KB |
Output is correct |
9 |
Correct |
27 ms |
4844 KB |
Output is correct |
10 |
Correct |
22 ms |
4160 KB |
Output is correct |
11 |
Correct |
9 ms |
1988 KB |
Output is correct |
12 |
Correct |
14 ms |
2152 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
37 ms |
6144 KB |
Output is correct |
15 |
Correct |
40 ms |
7588 KB |
Output is correct |
16 |
Correct |
7 ms |
1696 KB |
Output is correct |
17 |
Correct |
25 ms |
4816 KB |
Output is correct |
18 |
Correct |
14 ms |
3104 KB |
Output is correct |