#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[202], S[202], M;
vector<int> V0[202][4];
bool first = 1;
vector<int> encode(ll x){ ///reverse order
vector<int> ret;
for (int z=3;z<=M;z++){
if (x >= dp[z]) {x -= dp[z]; continue;}
if (x <= 1){
for (int i=z-3;i>=0;i--) ret.push_back(x^1);
ret.push_back(x);
ret.push_back(x);
return ret;
}
else if (x <= 3){
x -= 2;
for (int i=z-3;i>=0;i--) ret.push_back(x^1^(i&1));
ret.push_back(x);
ret.push_back(x);
return ret;
}
else if (x <= 3 + dp[z-2]){
x -= 4;
ret = encode(x + S[z-3]);
ret.push_back(ret.back());
ret.push_back(ret.back());
return ret;
}
else{
x -= 4 + dp[z-2];
ret = encode(x + S[z-4]);
ret.push_back(ret.back());
ret.push_back(ret.back()^1);
ret.push_back(ret.back());
return ret;
}
}
exit(1);
}
ll decode(vector<int> V){ ///reverse order
int L = V.size();
for (int i=0;i<4;i++) if (V==V0[L][i]) return S[L-1] + i;
if (V[(int)V.size()-3]==V.back()) return S[L-1] + 4 + (decode(vector<int>(V.begin(), V.end()-2)) - S[L-3]);
return S[L-1] + 4 + dp[L-2] + (decode(vector<int>(V.begin(), V.end()-3)) - S[L-4]);
}
void init(){
if (!first) return;
first = 0;
dp[0] = 0, S[0] = 0;
dp[1] = 0, S[1] = 0;
dp[2] = 0, S[2] = 0;
dp[3] = 2, S[3] = 2;
for (int i=4;i<202;i++){
dp[i] = dp[i-2] + dp[i-3] + 4;
S[i] = S[i-1] + dp[i];
if (S[i] >= (ll)1e18){
M = i;
break;
}
}
for (int i=3;i<=M;i++){
for (int j=0;j<(i==3?2:4);j++) V0[i][j] = encode(S[i-1] + j);
}
}
int Declare() {
init();
return 139;
}
std::pair<std::vector<int>, std::vector<int> > Anna(long long A) {
if (decode(encode(A))!=A){
auto V = encode(A);
printf("%lld -> ", A);
for (auto &x:V) printf("%d ", x);
printf("-> ");
printf("%lld\n", decode(V));
}
assert(decode(encode(A)) == A);
vector<int> ret[2];
ret[0] = encode(A);
ret[0].pop_back();
reverse(ret[0].begin(), ret[0].end());
/*printf("%lld -> ", A);
for (auto &x:ret[0]) printf("%d ", x);
printf("\n");*/
for (int i=0;i<(int)ret[0].size();i++) ret[1].push_back((i&1)^ret[0][0]);
return {ret[0], ret[1]};
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace {
ll dp[202], S[202], M;
vector<int> V0[202][4];
bool first = 1;
vector<int> encode(ll x){ ///reverse order
vector<int> ret;
for (int z=3;z<=M;z++){
if (x >= dp[z]) {x -= dp[z]; continue;}
if (x <= 1){
for (int i=z-3;i>=0;i--) ret.push_back(x^1);
ret.push_back(x);
ret.push_back(x);
return ret;
}
else if (x <= 3){
x -= 2;
for (int i=z-3;i>=0;i--) ret.push_back(x^1^(i&1));
ret.push_back(x);
ret.push_back(x);
return ret;
}
else if (x <= 3 + dp[z-2]){
x -= 4;
ret = encode(x + S[z-3]);
ret.push_back(ret.back());
ret.push_back(ret.back());
return ret;
}
else{
x -= 4 + dp[z-2];
ret = encode(x + S[z-4]);
ret.push_back(ret.back());
ret.push_back(ret.back()^1);
ret.push_back(ret.back());
return ret;
}
}
exit(1);
}
ll decode(vector<int> V){ ///reverse order
int L = V.size();
for (int i=0;i<4;i++) if (V==V0[L][i]) return S[L-1] + i;
if (V[(int)V.size()-3]==V.back()) return S[L-1] + 4 + (decode(vector<int>(V.begin(), V.end()-2)) - S[L-3]);
return S[L-1] + 4 + dp[L-2] + (decode(vector<int>(V.begin(), V.end()-3)) - S[L-4]);
}
void init(){
if (!first) return;
first = 0;
dp[0] = 0, S[0] = 0;
dp[1] = 0, S[1] = 0;
dp[2] = 0, S[2] = 0;
dp[3] = 2, S[3] = 2;
for (int i=4;i<202;i++){
dp[i] = dp[i-2] + dp[i-3] + 4;
S[i] = S[i-1] + dp[i];
if (S[i] >= (ll)1e18){
M = i;
break;
}
}
for (int i=3;i<=M;i++){
for (int j=0;j<(i==3?2:4);j++) V0[i][j] = encode(S[i-1] + j);
}
}
}
long long Bruno(std::vector<int> U) {
init();
vector<int> V = {1};
bool flag = 0;
if (!U[0]){
for (auto &x:U) x ^= 1;
flag = 1;
}
int x = 1, prv = 1, sum = 0;
for (int i=0;i<(int)U.size();i++){
sum += (U[i]?1:-1);
if (prv!=-1 && sum-x==2){
V.push_back(1);
V.push_back(1);
x = sum;
prv = 1;
}
if (prv!=1 && sum-x==-1){
V.push_back(0);
V.push_back(0);
x = sum-1;
prv = -1;
}
if (prv==-1 && sum-x==3){
V.push_back(1);
V.push_back(1);
V.push_back(1);
x = sum;
prv = 1;
}
if (prv==1 && sum-x==-2){
V.push_back(0);
V.push_back(0);
V.push_back(0);
x = sum-1;
prv = -1;
}
}
/*for (auto &x:V) printf("%d ", x);
printf("\n");*/
if (U.size()%4==2) sum--;
int sum2 = 0;
for (auto &x:V) sum2 += x?1:-1;
if (V.size()>U.size()/2) V.pop_back();
else if (V.size()<U.size()/2){
int d = U.size()/2 - V.size();
if (sum-sum2==d || sum-sum2==-d){
for (int i=0;i<d;i++) V.push_back(sum-sum2>=0);
}
else {
for (int i=0;i<d;i++) V.push_back(V.back()^1);
}
}
sum2 = 0;
for (auto &x:V) sum2 += x?1:-1;
assert(V.size()==U.size()/2);
assert(sum==sum2);
if (flag) for (auto &x:V) x ^= 1;
/*printf("Decode: ");
for (auto &x:V) printf("%d ", x);
printf("\n");*/
reverse(V.begin(), V.end());
V.push_back(V.back());
return decode(V);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
13 ms |
1272 KB |
Output is correct |
3 |
Correct |
17 ms |
1328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
13 ms |
1272 KB |
Output is correct |
3 |
Correct |
17 ms |
1328 KB |
Output is correct |
4 |
Correct |
30 ms |
1700 KB |
Output is correct |
5 |
Correct |
33 ms |
1820 KB |
Output is correct |
6 |
Correct |
31 ms |
1704 KB |
Output is correct |
7 |
Correct |
30 ms |
1748 KB |
Output is correct |
8 |
Correct |
29 ms |
1776 KB |
Output is correct |
9 |
Correct |
31 ms |
1820 KB |
Output is correct |
10 |
Correct |
30 ms |
1824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
13 ms |
1272 KB |
Output is correct |
3 |
Correct |
17 ms |
1328 KB |
Output is correct |
4 |
Correct |
30 ms |
1700 KB |
Output is correct |
5 |
Correct |
33 ms |
1820 KB |
Output is correct |
6 |
Correct |
31 ms |
1704 KB |
Output is correct |
7 |
Correct |
30 ms |
1748 KB |
Output is correct |
8 |
Correct |
29 ms |
1776 KB |
Output is correct |
9 |
Correct |
31 ms |
1820 KB |
Output is correct |
10 |
Correct |
30 ms |
1824 KB |
Output is correct |
11 |
Correct |
37 ms |
1788 KB |
Output is correct |
12 |
Correct |
31 ms |
1788 KB |
Output is correct |
13 |
Correct |
33 ms |
1980 KB |
Output is correct |
14 |
Correct |
31 ms |
1832 KB |
Output is correct |
15 |
Correct |
31 ms |
1808 KB |
Output is correct |
16 |
Correct |
31 ms |
1800 KB |
Output is correct |
17 |
Correct |
32 ms |
1876 KB |
Output is correct |
18 |
Correct |
27 ms |
1696 KB |
Output is correct |
19 |
Correct |
28 ms |
1748 KB |
Output is correct |
20 |
Correct |
28 ms |
1696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
13 ms |
1272 KB |
Output is correct |
3 |
Correct |
17 ms |
1328 KB |
Output is correct |
4 |
Correct |
30 ms |
1700 KB |
Output is correct |
5 |
Correct |
33 ms |
1820 KB |
Output is correct |
6 |
Correct |
31 ms |
1704 KB |
Output is correct |
7 |
Correct |
30 ms |
1748 KB |
Output is correct |
8 |
Correct |
29 ms |
1776 KB |
Output is correct |
9 |
Correct |
31 ms |
1820 KB |
Output is correct |
10 |
Correct |
30 ms |
1824 KB |
Output is correct |
11 |
Correct |
37 ms |
1788 KB |
Output is correct |
12 |
Correct |
31 ms |
1788 KB |
Output is correct |
13 |
Correct |
33 ms |
1980 KB |
Output is correct |
14 |
Correct |
31 ms |
1832 KB |
Output is correct |
15 |
Correct |
31 ms |
1808 KB |
Output is correct |
16 |
Correct |
31 ms |
1800 KB |
Output is correct |
17 |
Correct |
32 ms |
1876 KB |
Output is correct |
18 |
Correct |
27 ms |
1696 KB |
Output is correct |
19 |
Correct |
28 ms |
1748 KB |
Output is correct |
20 |
Correct |
28 ms |
1696 KB |
Output is correct |
21 |
Correct |
36 ms |
1920 KB |
Output is correct |
22 |
Correct |
36 ms |
1920 KB |
Output is correct |
23 |
Correct |
36 ms |
1992 KB |
Output is correct |
24 |
Correct |
35 ms |
1868 KB |
Output is correct |
25 |
Correct |
36 ms |
1996 KB |
Output is correct |
26 |
Correct |
41 ms |
2144 KB |
Output is correct |
27 |
Correct |
36 ms |
2008 KB |
Output is correct |
28 |
Correct |
31 ms |
1848 KB |
Output is correct |
29 |
Correct |
34 ms |
1872 KB |
Output is correct |
30 |
Correct |
31 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
13 ms |
1272 KB |
Output is correct |
3 |
Correct |
17 ms |
1328 KB |
Output is correct |
4 |
Correct |
30 ms |
1700 KB |
Output is correct |
5 |
Correct |
33 ms |
1820 KB |
Output is correct |
6 |
Correct |
31 ms |
1704 KB |
Output is correct |
7 |
Correct |
30 ms |
1748 KB |
Output is correct |
8 |
Correct |
29 ms |
1776 KB |
Output is correct |
9 |
Correct |
31 ms |
1820 KB |
Output is correct |
10 |
Correct |
30 ms |
1824 KB |
Output is correct |
11 |
Correct |
37 ms |
1788 KB |
Output is correct |
12 |
Correct |
31 ms |
1788 KB |
Output is correct |
13 |
Correct |
33 ms |
1980 KB |
Output is correct |
14 |
Correct |
31 ms |
1832 KB |
Output is correct |
15 |
Correct |
31 ms |
1808 KB |
Output is correct |
16 |
Correct |
31 ms |
1800 KB |
Output is correct |
17 |
Correct |
32 ms |
1876 KB |
Output is correct |
18 |
Correct |
27 ms |
1696 KB |
Output is correct |
19 |
Correct |
28 ms |
1748 KB |
Output is correct |
20 |
Correct |
28 ms |
1696 KB |
Output is correct |
21 |
Correct |
36 ms |
1920 KB |
Output is correct |
22 |
Correct |
36 ms |
1920 KB |
Output is correct |
23 |
Correct |
36 ms |
1992 KB |
Output is correct |
24 |
Correct |
35 ms |
1868 KB |
Output is correct |
25 |
Correct |
36 ms |
1996 KB |
Output is correct |
26 |
Correct |
41 ms |
2144 KB |
Output is correct |
27 |
Correct |
36 ms |
2008 KB |
Output is correct |
28 |
Correct |
31 ms |
1848 KB |
Output is correct |
29 |
Correct |
34 ms |
1872 KB |
Output is correct |
30 |
Correct |
31 ms |
1868 KB |
Output is correct |
31 |
Correct |
48 ms |
2468 KB |
Output is correct |
32 |
Correct |
53 ms |
2548 KB |
Output is correct |
33 |
Correct |
55 ms |
2504 KB |
Output is correct |
34 |
Correct |
49 ms |
2356 KB |
Output is correct |
35 |
Correct |
50 ms |
2220 KB |
Output is correct |
36 |
Correct |
50 ms |
2360 KB |
Output is correct |
37 |
Correct |
50 ms |
2368 KB |
Output is correct |
38 |
Correct |
47 ms |
2332 KB |
Output is correct |
39 |
Correct |
44 ms |
2256 KB |
Output is correct |
40 |
Correct |
44 ms |
2324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
3384 KB |
Output is correct |
2 |
Correct |
84 ms |
3324 KB |
Output is correct |
3 |
Correct |
87 ms |
3300 KB |
Output is correct |
4 |
Correct |
92 ms |
3428 KB |
Output is correct |
5 |
Correct |
87 ms |
3332 KB |
Output is correct |
6 |
Correct |
86 ms |
3412 KB |
Output is correct |
7 |
Correct |
96 ms |
3424 KB |
Output is correct |
8 |
Correct |
84 ms |
3328 KB |
Output is correct |
9 |
Correct |
83 ms |
3312 KB |
Output is correct |
10 |
Correct |
84 ms |
3368 KB |
Output is correct |
11 |
Correct |
97 ms |
3400 KB |
Output is correct |
12 |
Correct |
86 ms |
3380 KB |
Output is correct |
13 |
Correct |
88 ms |
3372 KB |
Output is correct |
14 |
Correct |
87 ms |
3744 KB |
Output is correct |
15 |
Correct |
80 ms |
3264 KB |
Output is correct |
16 |
Correct |
76 ms |
3332 KB |
Output is correct |
17 |
Correct |
75 ms |
3164 KB |
Output is correct |
18 |
Correct |
95 ms |
3296 KB |
Output is correct |
19 |
Correct |
80 ms |
3108 KB |
Output is correct |
20 |
Correct |
75 ms |
3112 KB |
Output is correct |