#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
const int MAX = 140;
bool inited = false;
vector<long long> D(MAX + 1);
void init()
{
if (inited)
return;
inited = true;
D[0] = 1, D[1] = 1, D[2] = 2;
for (int i = 3; i < MAX; i++)
D[i] = D[i - 2] + D[i - 3] + 1;
}
}
int Declare()
{
init();
return MAX;
}
pair<vector<int>, vector<int>> Asolve(int sz, long long A)
{
vector<int> U, V;
int lst = 0;
if (A >= D[sz - 1])
{
U.push_back(1);
V.push_back(1);
A -= D[sz - 1];
lst = 1;
}
else
{
U.push_back(0);
V.push_back(0);
lst = 0;
}
--sz;
for (int i = 0; i < sz; i++)
V.push_back(1 - V.back());
while (sz)
{
if (A == 0)
{
for (int i = 0; i < sz; i++)
U.push_back(1 - U.back());
sz = 0;
break;
}
--A;
if (lst == 1)
{
if (A >= (sz >= 3 ? D[sz - 3] : 0))
{
for (int i = 0; i < 2; i++)
U.push_back(1);
A -= (sz >= 3 ? D[sz - 3] : 0);
sz -= 2;
}
else
{
lst = 0;
for (int i = 0; i < 3; i++)
U.push_back(0);
sz -= 3;
}
}
else
{
if (A >= (sz >= 2 ? D[sz - 2] : 0))
{
lst = 1;
for (int i = 0; i < 3; i++)
U.push_back(1);
A -= (sz >= 2 ? D[sz - 2] : 0);
sz -= 3;
}
else
{
for (int i = 0; i < 2; i++)
U.push_back(0);
sz -= 2;
}
}
}
return {U, V};
}
pair<vector<int>, vector<int>> Anna(long long A)
{
--A;
for (int i = 1; i <= MAX; i++)
{
if (A >= 2 * D[i - 1])
A -= 2 * D[i - 1];
else
return Asolve(i, A);
}
cerr << A << endl;
assert(false);
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
const int MAX = 140;
bool inited = false;
vector<long long> D(MAX + 1);
void init()
{
if (inited)
return;
inited = true;
D[0] = 1, D[1] = 1, D[2] = 2;
for (int i = 3; i < MAX; i++)
D[i] = D[i - 2] + D[i - 3] + 1;
}
}
long long bsolve(vector<int> u)
{
int rem = u.size() / 2, state = 0, ulimit = 1, ucount = 1, dlimit = -1, dcount = 1;
long long ret = 0, uplus = D[rem - 1], dplus = 0;
for (int v : u)
{
state += v * 2 - 1;
if (state == ulimit)
{
ret += uplus, rem -= ucount;
ulimit = state + 2, ucount = 2;
uplus = (rem >= 3 ? D[rem - 3] : 0) + 1, dplus = 1;
dlimit = state - 2, dcount = 3;
}
else if (state == dlimit)
{
ret += dplus, rem -= dcount;
ulimit = state + 2, ucount = 3;
uplus = (rem >= 2 ? D[rem - 2] : 0) + 1, dplus = 1;
dlimit = state - 2, dcount = 2;
}
}
return ret;
}
long long Bruno(vector<int> u)
{
init();
long long ans = 1;
for (int i = 1; i < (int)u.size() / 2; i++)
ans += 2 * D[i - 1];
return ans + bsolve(u);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
792 KB |
Output is correct |
3 |
Correct |
15 ms |
948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
792 KB |
Output is correct |
3 |
Correct |
15 ms |
948 KB |
Output is correct |
4 |
Correct |
26 ms |
1192 KB |
Output is correct |
5 |
Correct |
24 ms |
1308 KB |
Output is correct |
6 |
Correct |
27 ms |
1380 KB |
Output is correct |
7 |
Correct |
26 ms |
1436 KB |
Output is correct |
8 |
Correct |
24 ms |
1304 KB |
Output is correct |
9 |
Correct |
29 ms |
1480 KB |
Output is correct |
10 |
Correct |
26 ms |
1312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
792 KB |
Output is correct |
3 |
Correct |
15 ms |
948 KB |
Output is correct |
4 |
Correct |
26 ms |
1192 KB |
Output is correct |
5 |
Correct |
24 ms |
1308 KB |
Output is correct |
6 |
Correct |
27 ms |
1380 KB |
Output is correct |
7 |
Correct |
26 ms |
1436 KB |
Output is correct |
8 |
Correct |
24 ms |
1304 KB |
Output is correct |
9 |
Correct |
29 ms |
1480 KB |
Output is correct |
10 |
Correct |
26 ms |
1312 KB |
Output is correct |
11 |
Correct |
27 ms |
1460 KB |
Output is correct |
12 |
Correct |
24 ms |
1404 KB |
Output is correct |
13 |
Correct |
28 ms |
1320 KB |
Output is correct |
14 |
Correct |
33 ms |
1336 KB |
Output is correct |
15 |
Correct |
26 ms |
1300 KB |
Output is correct |
16 |
Correct |
27 ms |
1388 KB |
Output is correct |
17 |
Correct |
25 ms |
1452 KB |
Output is correct |
18 |
Correct |
26 ms |
1180 KB |
Output is correct |
19 |
Correct |
23 ms |
1244 KB |
Output is correct |
20 |
Correct |
23 ms |
1328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
792 KB |
Output is correct |
3 |
Correct |
15 ms |
948 KB |
Output is correct |
4 |
Correct |
26 ms |
1192 KB |
Output is correct |
5 |
Correct |
24 ms |
1308 KB |
Output is correct |
6 |
Correct |
27 ms |
1380 KB |
Output is correct |
7 |
Correct |
26 ms |
1436 KB |
Output is correct |
8 |
Correct |
24 ms |
1304 KB |
Output is correct |
9 |
Correct |
29 ms |
1480 KB |
Output is correct |
10 |
Correct |
26 ms |
1312 KB |
Output is correct |
11 |
Correct |
27 ms |
1460 KB |
Output is correct |
12 |
Correct |
24 ms |
1404 KB |
Output is correct |
13 |
Correct |
28 ms |
1320 KB |
Output is correct |
14 |
Correct |
33 ms |
1336 KB |
Output is correct |
15 |
Correct |
26 ms |
1300 KB |
Output is correct |
16 |
Correct |
27 ms |
1388 KB |
Output is correct |
17 |
Correct |
25 ms |
1452 KB |
Output is correct |
18 |
Correct |
26 ms |
1180 KB |
Output is correct |
19 |
Correct |
23 ms |
1244 KB |
Output is correct |
20 |
Correct |
23 ms |
1328 KB |
Output is correct |
21 |
Correct |
30 ms |
1620 KB |
Output is correct |
22 |
Correct |
28 ms |
1620 KB |
Output is correct |
23 |
Correct |
31 ms |
1596 KB |
Output is correct |
24 |
Correct |
27 ms |
1544 KB |
Output is correct |
25 |
Correct |
28 ms |
1504 KB |
Output is correct |
26 |
Correct |
30 ms |
1584 KB |
Output is correct |
27 |
Correct |
35 ms |
1472 KB |
Output is correct |
28 |
Correct |
27 ms |
1452 KB |
Output is correct |
29 |
Correct |
26 ms |
1444 KB |
Output is correct |
30 |
Correct |
26 ms |
1440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
792 KB |
Output is correct |
3 |
Correct |
15 ms |
948 KB |
Output is correct |
4 |
Correct |
26 ms |
1192 KB |
Output is correct |
5 |
Correct |
24 ms |
1308 KB |
Output is correct |
6 |
Correct |
27 ms |
1380 KB |
Output is correct |
7 |
Correct |
26 ms |
1436 KB |
Output is correct |
8 |
Correct |
24 ms |
1304 KB |
Output is correct |
9 |
Correct |
29 ms |
1480 KB |
Output is correct |
10 |
Correct |
26 ms |
1312 KB |
Output is correct |
11 |
Correct |
27 ms |
1460 KB |
Output is correct |
12 |
Correct |
24 ms |
1404 KB |
Output is correct |
13 |
Correct |
28 ms |
1320 KB |
Output is correct |
14 |
Correct |
33 ms |
1336 KB |
Output is correct |
15 |
Correct |
26 ms |
1300 KB |
Output is correct |
16 |
Correct |
27 ms |
1388 KB |
Output is correct |
17 |
Correct |
25 ms |
1452 KB |
Output is correct |
18 |
Correct |
26 ms |
1180 KB |
Output is correct |
19 |
Correct |
23 ms |
1244 KB |
Output is correct |
20 |
Correct |
23 ms |
1328 KB |
Output is correct |
21 |
Correct |
30 ms |
1620 KB |
Output is correct |
22 |
Correct |
28 ms |
1620 KB |
Output is correct |
23 |
Correct |
31 ms |
1596 KB |
Output is correct |
24 |
Correct |
27 ms |
1544 KB |
Output is correct |
25 |
Correct |
28 ms |
1504 KB |
Output is correct |
26 |
Correct |
30 ms |
1584 KB |
Output is correct |
27 |
Correct |
35 ms |
1472 KB |
Output is correct |
28 |
Correct |
27 ms |
1452 KB |
Output is correct |
29 |
Correct |
26 ms |
1444 KB |
Output is correct |
30 |
Correct |
26 ms |
1440 KB |
Output is correct |
31 |
Correct |
41 ms |
1968 KB |
Output is correct |
32 |
Correct |
45 ms |
1932 KB |
Output is correct |
33 |
Correct |
38 ms |
1908 KB |
Output is correct |
34 |
Correct |
37 ms |
1988 KB |
Output is correct |
35 |
Correct |
37 ms |
1940 KB |
Output is correct |
36 |
Correct |
41 ms |
1996 KB |
Output is correct |
37 |
Correct |
40 ms |
1928 KB |
Output is correct |
38 |
Correct |
33 ms |
1792 KB |
Output is correct |
39 |
Correct |
36 ms |
1856 KB |
Output is correct |
40 |
Correct |
35 ms |
1840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
2776 KB |
Output is correct |
2 |
Correct |
60 ms |
2888 KB |
Output is correct |
3 |
Correct |
60 ms |
2812 KB |
Output is correct |
4 |
Correct |
61 ms |
2760 KB |
Output is correct |
5 |
Correct |
63 ms |
2776 KB |
Output is correct |
6 |
Correct |
75 ms |
2812 KB |
Output is correct |
7 |
Correct |
64 ms |
2796 KB |
Output is correct |
8 |
Correct |
59 ms |
2848 KB |
Output is correct |
9 |
Correct |
63 ms |
2840 KB |
Output is correct |
10 |
Correct |
68 ms |
2844 KB |
Output is correct |
11 |
Correct |
60 ms |
2776 KB |
Output is correct |
12 |
Correct |
63 ms |
2768 KB |
Output is correct |
13 |
Correct |
57 ms |
2836 KB |
Output is correct |
14 |
Correct |
59 ms |
2672 KB |
Output is correct |
15 |
Correct |
57 ms |
2644 KB |
Output is correct |
16 |
Correct |
55 ms |
2636 KB |
Output is correct |
17 |
Correct |
55 ms |
2836 KB |
Output is correct |
18 |
Correct |
55 ms |
2640 KB |
Output is correct |
19 |
Correct |
68 ms |
2568 KB |
Output is correct |
20 |
Correct |
57 ms |
2728 KB |
Output is correct |