#include "doll.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
bool bo[200001];
int st[200001];
void create_circuit(int M, vector<int> A) {
A.pub(0);
int N = A.size();
vector<int> C(M + 1);
set<int> ext;
for (int i = 1; i <= M; i++)
C[i] = -1;
C[0] = A[0];
ext.insert(1);
vector<int> X, Y;
while (ext.size() * 2 < A.size() - 1 || pow(2, (int)log2(ext.size())) != ext.size() )
{
auto it = ext.begin();
while ( X.size() < *it )
X.pub(1e9), Y.pub(1e9);
X[*it - 1] = -(*it * 2);
Y[*it - 1] = -(*it * 2 + 1);
ext.insert(*it * 2);
ext.insert(*it * 2 + 1);
while ( *it * 2 + 1 > X.size() )
{
X.pub(1e9);
Y.pub(1e9);
}
ext.erase(it);
}
int num = 0, u = 0, z = 1, p = 2 * ext.size() - (A.size() - 1);
while ( num < ext.size() * 2 )
{
// cout << u << "\n";
if ( (X[u] == 1e9 && !st[u]) || (Y[u] == 1e9 && st[u]) )
{
if ( z < A.size() && !p )
{
if ( !st[u] )
{
X[u] = A[z++];
st[u] = 1;
} else
{
Y[u] = A[z++];
st[u] = 0;
}
} else {
if ( !st[u] )
{
X[u] = -1;
st[u] = 1;
} else
{
Y[u] = -1;
st[u] = 0;
}
p--;
}
u = 0;
num++;
} else {
if ( st[u] )
{
st[u] ^= 1;
u = -Y[u] - 1;
} else
st[u] ^= 1, u = -X[u] - 1;
}
}
// for (auto x : C)
// cout << x << " ";
//
// cout << "\n";
//
// for (auto x : X)
// cout << x << " ";
//
// cout << "\n";
//
// for (auto x : Y)
// cout << x << " ";
//
// cout << "\n";
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:43:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
43 | while ( X.size() < *it )
| ~~~~~~~~~^~~~~
doll.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | while ( *it * 2 + 1 > X.size() )
| ~~~~~~~~~~~~^~~~~~~~~~
doll.cpp:60:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | while ( num < ext.size() * 2 )
| ~~~~^~~~~~~~~~~~~~~~
doll.cpp:65:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | if ( z < A.size() && !p )
| ~~^~~~~~~~~~
doll.cpp:30:6: warning: unused variable 'N' [-Wunused-variable]
30 | int N = A.size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 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 |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
204 KB |
Output is partially correct |
2 |
Correct |
93 ms |
8608 KB |
Output is correct |
3 |
Runtime error |
102 ms |
20140 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
204 KB |
Output is partially correct |
2 |
Correct |
93 ms |
8608 KB |
Output is correct |
3 |
Runtime error |
102 ms |
20140 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |