This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+1;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
void make(int &s, int cnt, int root, int idx, int lvl, vector<int> &X, vector<int> &Y) {
if(lvl == 2) {
if(cnt == 1) X[idx] = root;
else X[idx] = INF;
Y[idx] = INF;
} else {
if(cnt > lvl/2) {
X[idx] = -(++s);
X.push_back(0); Y.push_back(0);
make(s, cnt-lvl/2, root, -X[idx]-1, lvl/2, X, Y);
Y[idx] = -(++s);
X.push_back(0); Y.push_back(0);
make(s, lvl/2, root, -Y[idx]-1, lvl/2, X, Y);
} else {
X[idx] = root;
Y[idx] = -(++s);
X.push_back(0); Y.push_back(0);
make(s, cnt, root, -Y[idx]-1, lvl/2, X, Y);
}
}
}
void solve(int &c, vector<int> &X, vector<int> &Y, vector<int> &nxt) {
if(nxt.size() == 0) {
c = 0;
} else if(nxt.size() == 1) {
c = nxt[0];
} else {
int s = 0;
c = -(++s);
X.push_back(0); Y.push_back(0);
int lvl = 1;
while(lvl < nxt.size()) lvl <<= 1;
make(s, nxt.size(), c, -c-1, lvl, X, Y);
int here = c, cnt = 0;
vector<bool> chk(s+c+1, true);
while(cnt < nxt.size()) {
//cout << here << " " << c << "\n";
int& there = (chk[-here+c] ? X[-here-1] : Y[-here-1]);
chk[-here+c] = !chk[-here+c];
if(there == INF) {
there = nxt[cnt++];
here = c;
} else here = there;
}
}
}
void create_circuit(int M, vector<int> A) {
vector<int> C(M+1, -1), X, Y;
A.push_back(0);
solve(C[0], X, Y, A);
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'void solve(int&, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
doll.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | while(lvl < nxt.size()) lvl <<= 1;
| ~~~~^~~~~~~~~~~~
doll.cpp:55:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while(cnt < nxt.size()) {
| ~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |