#include "Annalib.h"
#include <bits/stdc++.h>
using namespace std;
void Anna(int N, long long X, int K, int P[])
{
map<vector<int>, vector<int>> M;
M[{1, 1}] = {1, 1, 1};
M[{1}] = {1, 1, 0};
M[{1, 0}] = {1, 0, 1};
M[{0}] = {1, 0, 0};
M[{0, 1}] = {0, 1, 1};
M[{0, 0}] = {0, 1, 0};
vector<int> P2(N);
for (int i = 0; i < K; i++)
P2[P[i]] = 1;
vector<int> ans(N);
int buff = 0;
vector<int> bits;
while (X)
{
bits.push_back(X % 2);
X /= 2;
}
while (bits.size() < 60)
bits.push_back(0);
reverse(bits.begin(), bits.end());
for (int i = 0; i < N; i += 3)
{
if (buff == bits.size())
break;
vector<int> temp;
if (P2[i] + P2[i + 1] + P2[i + 2] > 1)
continue;
if (P2[i] == 1)
{
if (bits[buff] == 1)
{
temp = {0, 0, 1};
buff++;
}
else if (buff < bits.size() - 1 && bits[buff] == 0)
{
temp = M[{bits[buff], bits[buff + 1]}];
buff += 2;
}
else
{
temp = {0, 1, 0};
buff++;
}
}
else if (P2[i + 1] == 1)
{
if (bits[buff] == 1)
temp = {0, 0, 1};
else
temp = {1, 0, 0};
buff++;
}
else if (P2[i + 2] == 1)
{
if (bits[buff] == 1)
temp = {1, 1, 0};
else
temp = {1, 0, 0};
buff++;
}
else
{
if (buff < bits.size() - 1)
{
temp = M[{bits[buff], bits[buff + 1]}];
buff += 2;
}
else
{
temp = M[{bits[buff]}];
buff++;
}
}
if (!temp.empty())
ans[i] = temp[0], ans[i + 1] = temp[1], ans[i + 2] = temp[2];
}
for (int i = 0; i < N; i++)
{
// cout << ans[i] << ' ';
Set(i, ans[i]);
}
}
/*int main()
{
long long N, X, K;
cin >> N >> X >> K;
int P[N];
srand(time(0));
for (long long i = 0; i < K; i++)
P[i] = rand() % N;
Anna(N, X, K, P);
}*/
#include "Brunolib.h"
#include <bits/stdc++.h>
using namespace std;
long long Bruno(int N, int A[])
{
map<vector<int>, vector<int>> M;
M[{1, 1, 1}] = {1, 1};
M[{1, 1, 0}] = {1};
M[{1, 0, 1}] = {1, 0};
M[{1, 0, 0}] = {0};
M[{0, 1, 1}] = {0, 1};
M[{0, 1, 0}] = {0, 0};
M[{0, 0, 1}] = {1};
long long X = 0;
int compte = 0;
for (int i = 0; i < N; i += 3)
{
vector<int> temp = {A[i], A[i + 1], A[i + 2]};
if (temp[0] + temp[1] + temp[2] == 0)
continue;
else
temp = M[temp];
for (int j = 0; j < temp.size(); j++)
{
X *= 2;
X += temp[j];
compte++;
}
}
if (compte > 60)
X /= 2;
return X;
}
/*int main()
{
int N;
cin >> N;
int A[N];
for (int i = 0; i < N; i++)
cin >> A[i];
cout << Bruno(N, A);
}*/
Compilation message
Anna.cpp: In function 'void Anna(int, long long int, int, int*)':
Anna.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if (buff == bits.size())
| ~~~~~^~~~~~~~~~~~~~
Anna.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | else if (buff < bits.size() - 1 && bits[buff] == 0)
| ~~~~~^~~~~~~~~~~~~~~~~
Anna.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | if (buff < bits.size() - 1)
| ~~~~~^~~~~~~~~~~~~~~~~
Bruno.cpp: In function 'long long int Bruno(int, int*)':
Bruno.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int j = 0; j < temp.size(); j++)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2396 KB |
Output is correct - L* = 40 |
2 |
Correct |
27 ms |
2552 KB |
Output is correct - L* = 40 |
3 |
Correct |
25 ms |
2396 KB |
Output is correct - L* = 40 |
4 |
Correct |
25 ms |
2404 KB |
Output is correct - L* = 40 |
5 |
Correct |
26 ms |
2368 KB |
Output is correct - L* = 40 |
6 |
Correct |
24 ms |
2656 KB |
Output is correct - L* = 40 |
7 |
Correct |
25 ms |
2624 KB |
Output is correct - L* = 40 |
8 |
Correct |
32 ms |
2396 KB |
Output is correct - L* = 40 |
9 |
Correct |
25 ms |
2468 KB |
Output is correct - L* = 40 |
10 |
Correct |
26 ms |
2400 KB |
Output is correct - L* = 40 |
11 |
Correct |
25 ms |
2368 KB |
Output is correct - L* = 40 |
12 |
Correct |
23 ms |
2404 KB |
Output is correct - L* = 40 |
13 |
Correct |
25 ms |
2372 KB |
Output is correct - L* = 40 |
14 |
Correct |
26 ms |
2396 KB |
Output is correct - L* = 40 |
15 |
Correct |
25 ms |
2404 KB |
Output is correct - L* = 40 |
16 |
Correct |
24 ms |
2404 KB |
Output is correct - L* = 40 |
17 |
Correct |
23 ms |
2396 KB |
Output is correct - L* = 40 |
18 |
Correct |
27 ms |
2396 KB |
Output is correct - L* = 40 |
19 |
Correct |
24 ms |
2396 KB |
Output is correct - L* = 40 |
20 |
Correct |
24 ms |
2404 KB |
Output is correct - L* = 40 |
21 |
Correct |
26 ms |
2396 KB |
Output is correct - L* = 40 |
22 |
Correct |
25 ms |
2372 KB |
Output is correct - L* = 40 |
23 |
Correct |
25 ms |
2372 KB |
Output is correct - L* = 40 |
24 |
Correct |
25 ms |
2400 KB |
Output is correct - L* = 40 |
25 |
Correct |
24 ms |
2392 KB |
Output is correct - L* = 40 |
26 |
Correct |
27 ms |
2372 KB |
Output is correct - L* = 40 |
27 |
Correct |
28 ms |
2396 KB |
Output is correct - L* = 40 |
28 |
Correct |
27 ms |
2476 KB |
Output is correct - L* = 40 |
29 |
Correct |
30 ms |
2368 KB |
Output is correct - L* = 40 |
30 |
Correct |
25 ms |
2584 KB |
Output is correct - L* = 40 |
31 |
Correct |
25 ms |
2396 KB |
Output is correct - L* = 40 |
32 |
Correct |
24 ms |
2476 KB |
Output is correct - L* = 40 |
33 |
Correct |
28 ms |
2648 KB |
Output is correct - L* = 40 |
34 |
Correct |
24 ms |
2652 KB |
Output is correct - L* = 40 |
35 |
Correct |
25 ms |
2400 KB |
Output is correct - L* = 40 |
36 |
Correct |
24 ms |
2476 KB |
Output is correct - L* = 40 |
37 |
Correct |
24 ms |
2400 KB |
Output is correct - L* = 40 |
38 |
Correct |
26 ms |
2480 KB |
Output is correct - L* = 40 |
39 |
Correct |
28 ms |
2404 KB |
Output is correct - L* = 40 |
40 |
Correct |
24 ms |
2632 KB |
Output is correct - L* = 40 |