#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
const int MAX = 141;
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;
for (int i = 0; i < sz; i++)
V.push_back(i & 1);
int lst = 0;
for (int i = 0; i < 2; i++)
U.push_back(A >= D[sz - 2] ? 1 : 0);
if (A >= D[sz - 2])
A -= D[sz - 2], lst = 1;
sz -= 2;
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 = 2; i <= MAX; i++)
{
if (A >= 2 * D[i - 2])
A -= 2 * D[i - 2];
else
return Asolve(i, A);
}
assert(false);
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
const int MAX = 150;
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 N = u.size() / 2, rem = N, prv = -1;
long long ret = -1;
int state = 1, ulimit = 3, ucount = 2;
long long uplus = D[rem - 2];
int dlimit = -3, dcount = 2;
for (int v : u)
{
state += v * 4 - 2;
if (state == ulimit)
{
ret += uplus + 1;
rem -= ucount;
ulimit = state + 4;
ucount = 2;
uplus = rem >= 3 ? D[rem - 3] : 0;
dlimit = state - 4;
dcount = 3;
}
else if (state == dlimit)
{
ret += 1;
rem -= dcount;
ulimit = state + 4;
ucount = 3;
uplus = rem >= 2 ? D[rem - 2] : 0;
dlimit = state - 4;
dcount = 2;
}
}
return ret;
}
long long Bruno(vector<int> u)
{
init();
long long ans = 1;
for (int i = 2; i < (int)u.size() / 2; i++)
ans += 2 * D[i - 2];
return ans + bsolve(u);
}
Compilation message
Bruno.cpp: In function 'long long int bsolve(std::vector<int>)':
Bruno.cpp:23:36: warning: unused variable 'prv' [-Wunused-variable]
23 | int N = u.size() / 2, rem = N, prv = -1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
516 KB |
Output is correct |
2 |
Correct |
13 ms |
888 KB |
Output is correct |
3 |
Correct |
15 ms |
928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
516 KB |
Output is correct |
2 |
Correct |
13 ms |
888 KB |
Output is correct |
3 |
Correct |
15 ms |
928 KB |
Output is correct |
4 |
Correct |
24 ms |
1324 KB |
Output is correct |
5 |
Correct |
25 ms |
1220 KB |
Output is correct |
6 |
Correct |
28 ms |
1364 KB |
Output is correct |
7 |
Correct |
28 ms |
1412 KB |
Output is correct |
8 |
Correct |
25 ms |
1388 KB |
Output is correct |
9 |
Correct |
25 ms |
1340 KB |
Output is correct |
10 |
Correct |
24 ms |
1288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
516 KB |
Output is correct |
2 |
Correct |
13 ms |
888 KB |
Output is correct |
3 |
Correct |
15 ms |
928 KB |
Output is correct |
4 |
Correct |
24 ms |
1324 KB |
Output is correct |
5 |
Correct |
25 ms |
1220 KB |
Output is correct |
6 |
Correct |
28 ms |
1364 KB |
Output is correct |
7 |
Correct |
28 ms |
1412 KB |
Output is correct |
8 |
Correct |
25 ms |
1388 KB |
Output is correct |
9 |
Correct |
25 ms |
1340 KB |
Output is correct |
10 |
Correct |
24 ms |
1288 KB |
Output is correct |
11 |
Correct |
26 ms |
1388 KB |
Output is correct |
12 |
Correct |
26 ms |
1340 KB |
Output is correct |
13 |
Correct |
27 ms |
1384 KB |
Output is correct |
14 |
Correct |
25 ms |
1368 KB |
Output is correct |
15 |
Correct |
25 ms |
1340 KB |
Output is correct |
16 |
Correct |
25 ms |
1352 KB |
Output is correct |
17 |
Correct |
25 ms |
1280 KB |
Output is correct |
18 |
Correct |
23 ms |
1260 KB |
Output is correct |
19 |
Correct |
23 ms |
1360 KB |
Output is correct |
20 |
Correct |
24 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
516 KB |
Output is correct |
2 |
Correct |
13 ms |
888 KB |
Output is correct |
3 |
Correct |
15 ms |
928 KB |
Output is correct |
4 |
Correct |
24 ms |
1324 KB |
Output is correct |
5 |
Correct |
25 ms |
1220 KB |
Output is correct |
6 |
Correct |
28 ms |
1364 KB |
Output is correct |
7 |
Correct |
28 ms |
1412 KB |
Output is correct |
8 |
Correct |
25 ms |
1388 KB |
Output is correct |
9 |
Correct |
25 ms |
1340 KB |
Output is correct |
10 |
Correct |
24 ms |
1288 KB |
Output is correct |
11 |
Correct |
26 ms |
1388 KB |
Output is correct |
12 |
Correct |
26 ms |
1340 KB |
Output is correct |
13 |
Correct |
27 ms |
1384 KB |
Output is correct |
14 |
Correct |
25 ms |
1368 KB |
Output is correct |
15 |
Correct |
25 ms |
1340 KB |
Output is correct |
16 |
Correct |
25 ms |
1352 KB |
Output is correct |
17 |
Correct |
25 ms |
1280 KB |
Output is correct |
18 |
Correct |
23 ms |
1260 KB |
Output is correct |
19 |
Correct |
23 ms |
1360 KB |
Output is correct |
20 |
Correct |
24 ms |
1364 KB |
Output is correct |
21 |
Correct |
28 ms |
1532 KB |
Output is correct |
22 |
Correct |
27 ms |
1544 KB |
Output is correct |
23 |
Correct |
30 ms |
1532 KB |
Output is correct |
24 |
Correct |
27 ms |
1620 KB |
Output is correct |
25 |
Correct |
27 ms |
1580 KB |
Output is correct |
26 |
Correct |
30 ms |
1496 KB |
Output is correct |
27 |
Correct |
27 ms |
1616 KB |
Output is correct |
28 |
Correct |
26 ms |
1476 KB |
Output is correct |
29 |
Correct |
26 ms |
1468 KB |
Output is correct |
30 |
Correct |
28 ms |
1424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
516 KB |
Output is correct |
2 |
Correct |
13 ms |
888 KB |
Output is correct |
3 |
Correct |
15 ms |
928 KB |
Output is correct |
4 |
Correct |
24 ms |
1324 KB |
Output is correct |
5 |
Correct |
25 ms |
1220 KB |
Output is correct |
6 |
Correct |
28 ms |
1364 KB |
Output is correct |
7 |
Correct |
28 ms |
1412 KB |
Output is correct |
8 |
Correct |
25 ms |
1388 KB |
Output is correct |
9 |
Correct |
25 ms |
1340 KB |
Output is correct |
10 |
Correct |
24 ms |
1288 KB |
Output is correct |
11 |
Correct |
26 ms |
1388 KB |
Output is correct |
12 |
Correct |
26 ms |
1340 KB |
Output is correct |
13 |
Correct |
27 ms |
1384 KB |
Output is correct |
14 |
Correct |
25 ms |
1368 KB |
Output is correct |
15 |
Correct |
25 ms |
1340 KB |
Output is correct |
16 |
Correct |
25 ms |
1352 KB |
Output is correct |
17 |
Correct |
25 ms |
1280 KB |
Output is correct |
18 |
Correct |
23 ms |
1260 KB |
Output is correct |
19 |
Correct |
23 ms |
1360 KB |
Output is correct |
20 |
Correct |
24 ms |
1364 KB |
Output is correct |
21 |
Correct |
28 ms |
1532 KB |
Output is correct |
22 |
Correct |
27 ms |
1544 KB |
Output is correct |
23 |
Correct |
30 ms |
1532 KB |
Output is correct |
24 |
Correct |
27 ms |
1620 KB |
Output is correct |
25 |
Correct |
27 ms |
1580 KB |
Output is correct |
26 |
Correct |
30 ms |
1496 KB |
Output is correct |
27 |
Correct |
27 ms |
1616 KB |
Output is correct |
28 |
Correct |
26 ms |
1476 KB |
Output is correct |
29 |
Correct |
26 ms |
1468 KB |
Output is correct |
30 |
Correct |
28 ms |
1424 KB |
Output is correct |
31 |
Correct |
39 ms |
1964 KB |
Output is correct |
32 |
Correct |
38 ms |
1996 KB |
Output is correct |
33 |
Correct |
41 ms |
2032 KB |
Output is correct |
34 |
Correct |
38 ms |
1880 KB |
Output is correct |
35 |
Correct |
39 ms |
1980 KB |
Output is correct |
36 |
Correct |
39 ms |
1856 KB |
Output is correct |
37 |
Correct |
37 ms |
1840 KB |
Output is correct |
38 |
Correct |
34 ms |
1816 KB |
Output is correct |
39 |
Correct |
36 ms |
1764 KB |
Output is correct |
40 |
Correct |
34 ms |
1812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
62 ms |
2828 KB |
Output is partially correct |
2 |
Partially correct |
64 ms |
2872 KB |
Output is partially correct |
3 |
Partially correct |
59 ms |
2808 KB |
Output is partially correct |
4 |
Partially correct |
59 ms |
2880 KB |
Output is partially correct |
5 |
Partially correct |
59 ms |
2908 KB |
Output is partially correct |
6 |
Partially correct |
59 ms |
2876 KB |
Output is partially correct |
7 |
Partially correct |
59 ms |
2780 KB |
Output is partially correct |
8 |
Partially correct |
60 ms |
2776 KB |
Output is partially correct |
9 |
Partially correct |
61 ms |
2888 KB |
Output is partially correct |
10 |
Partially correct |
61 ms |
2836 KB |
Output is partially correct |
11 |
Partially correct |
63 ms |
2812 KB |
Output is partially correct |
12 |
Partially correct |
59 ms |
2796 KB |
Output is partially correct |
13 |
Partially correct |
63 ms |
2792 KB |
Output is partially correct |
14 |
Partially correct |
57 ms |
2800 KB |
Output is partially correct |
15 |
Partially correct |
53 ms |
2760 KB |
Output is partially correct |
16 |
Partially correct |
53 ms |
2708 KB |
Output is partially correct |
17 |
Partially correct |
52 ms |
2628 KB |
Output is partially correct |
18 |
Partially correct |
55 ms |
2596 KB |
Output is partially correct |
19 |
Partially correct |
52 ms |
2728 KB |
Output is partially correct |
20 |
Partially correct |
52 ms |
2780 KB |
Output is partially correct |