#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
void create_circuit(int m, vector<int> a);
namespace Grader{
vector<int> a;
void answer(vector<int> C, vector<int> X, vector<int> Y){
cout << "C: ";
printArr(C);
cout << "X: ";
printArr(X);
cout << "Y: ";
printArr(Y);
cout << "Validating...\n";
int ball = 0;
vector<int> ans;
vector<bool> state(X.size());
while(ball != 0 || ans.empty()){
cout << "Ball: " << ball << endl;
if (ball > 0) ans.push_back(ball);
if (ball >= 0){
ball = C[ball];
}
else {
int cur = (-ball) - 1;
if (state[cur]){
state[cur] = false;
ball = Y[cur];
}
else{
state[cur] = true;
ball = X[cur];
}
}
}
if (ans != a) cout << "Wrong answer! (incorrect sequence produced)\n";
else if (*max_element(ALL(state)) == 1) cout << "Wrong answer! (there exists an Y switch)\n";
else cout << "Correct answer!\n";
}
void solve(){
int n, m; cin >> n >> m;
a = vector<int>(n);
for(int i = 0; i<n; ++i) cin >> a[i];
create_circuit(m, a);
}
}
// using namespace Grader;
void toss(vector<int> &a){
int n = a.size();
vector<int> st(n*2);
for(int i: a){
int idx = 1;
while(idx < n){
if (!st[idx]){
st[idx] = 1;
idx = idx * 2;
}
else{
st[idx] = 0;
idx = idx * 2 + 1;
}
}
st[idx] = i;
}
for(int i = n; i<n*2; ++i) a[i-n] = st[i];
}
void create_circuit(int m, vector<int> a) {
vector<int> C(m+1, 0);
vector<int> X, Y;
int n = a.size();
a.push_back(-1);
vector<vector<int>> fw(m+1);
for(int i = 0; i<n; ++i){
fw[a[i]].push_back(a[i+1]);
}
fw[0].push_back(a[0]);
X.push_back(0); Y.push_back(0);
int cur = -1;
int last = -1;
for(int i = 0; i<=m; ++i) {
int k = fw[i].size();
if (k == 0) continue;
if (k == 1) {C[i] = fw[i][0]; continue;}
if (k != LASTBIT(k)){
while(fw[i].size() != LASTBIT(fw[i].size())) fw[i].push_back(cur-1);
fw[i].back() = last;
last = cur-1;
k = fw[i].size();
}
C[i] = cur-1;
toss(fw[i]);
vector<int> mariana(k);
for(int i = 1; i<k; ++i) mariana[i] = --cur;
for(int j: fw[i]) mariana.push_back(j);
for(int i = 1; i<k; ++i){
X.push_back(mariana[i * 2]);
Y.push_back(mariana[i * 2 + 1]);
}
}
X[0] = last;
answer(C, X, Y);
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// solve();
// return 0;
// }
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:142:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
142 | while(fw[i].size() != LASTBIT(fw[i].size())) fw[i].push_back(cur-1);
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
7000 KB |
Output is correct |
3 |
Correct |
14 ms |
5720 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
3932 KB |
Output is correct |
6 |
Correct |
23 ms |
8416 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
7000 KB |
Output is correct |
3 |
Correct |
14 ms |
5720 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
3932 KB |
Output is correct |
6 |
Correct |
23 ms |
8416 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
32 ms |
8272 KB |
Output is correct |
9 |
Correct |
33 ms |
9556 KB |
Output is correct |
10 |
Correct |
51 ms |
12864 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
7000 KB |
Output is correct |
3 |
Correct |
14 ms |
5720 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
3932 KB |
Output is correct |
6 |
Correct |
23 ms |
8416 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
32 ms |
8272 KB |
Output is correct |
9 |
Correct |
33 ms |
9556 KB |
Output is correct |
10 |
Correct |
51 ms |
12864 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
57 ms |
12528 KB |
Output is correct |
15 |
Correct |
30 ms |
7104 KB |
Output is correct |
16 |
Correct |
44 ms |
10304 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
52 ms |
12072 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
34 ms |
7508 KB |
Output is correct |
3 |
Partially correct |
55 ms |
10948 KB |
Output is partially correct |
4 |
Partially correct |
62 ms |
11804 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
34 ms |
7508 KB |
Output is correct |
3 |
Partially correct |
55 ms |
10948 KB |
Output is partially correct |
4 |
Partially correct |
62 ms |
11804 KB |
Output is partially correct |
5 |
Partially correct |
61 ms |
13876 KB |
Output is partially correct |
6 |
Partially correct |
65 ms |
14292 KB |
Output is partially correct |
7 |
Partially correct |
64 ms |
13984 KB |
Output is partially correct |
8 |
Partially correct |
73 ms |
14452 KB |
Output is partially correct |
9 |
Partially correct |
54 ms |
13384 KB |
Output is partially correct |
10 |
Partially correct |
93 ms |
17468 KB |
Output is partially correct |
11 |
Partially correct |
69 ms |
14660 KB |
Output is partially correct |
12 |
Partially correct |
40 ms |
9868 KB |
Output is partially correct |
13 |
Partially correct |
39 ms |
9340 KB |
Output is partially correct |
14 |
Partially correct |
41 ms |
9084 KB |
Output is partially correct |
15 |
Partially correct |
39 ms |
9092 KB |
Output is partially correct |
16 |
Partially correct |
1 ms |
600 KB |
Output is partially correct |
17 |
Partially correct |
33 ms |
8168 KB |
Output is partially correct |
18 |
Partially correct |
33 ms |
8056 KB |
Output is partially correct |
19 |
Partially correct |
35 ms |
9304 KB |
Output is partially correct |
20 |
Partially correct |
53 ms |
11328 KB |
Output is partially correct |
21 |
Partially correct |
80 ms |
12828 KB |
Output is partially correct |
22 |
Partially correct |
43 ms |
10824 KB |
Output is partially correct |