이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "doll.h"
//#include "grader.cpp"
using namespace std;
const int maxn = (int)1e6 + 7;
const int inf = (int)1e6 + 6;
int sz;
void solve5(int M, vector<int> A) {
int N = A.size();
vector<int> C(M + 1);
vector<int> X, Y;
C[0] = A[0];
int tmp = N - 1;
while (tmp > 0) {
sz++;
tmp >>= 1;
}
if (sz) C[1] = -1;
else C[1] = 0;
X.resize(sz);
Y.resize(sz);
tmp = N - 1;
for (int i = 1; i <= sz; i++) {
if ((tmp >> (sz - i)) & 1) {
X[i - 1] = A[0];
} else {
X[i - 1] = -1;
}
Y[i - 1] = ((i == sz) ? 0 : -(i + 1));
}
answer(C, X, Y);
}
vector <int> X, Y;
int cnt[maxn];
void add(int val, int v, int l, int r) {
int mid = (l + r) >> 1;
if (cnt[v + v] == cnt[v + v + 1]) {
cnt[v + v + 1]++;
if (mid + 1 == r) {
Y[v + sz - 1] = val;
} else {
add(val, v + v + 1, mid + 1, r);
}
} else {
cnt[v + v]++;
if (l == mid) {
X[v + sz - 1] = val;
} else {
add(val, v + v, l, mid);
}
}
cnt[v]++;
}
void solve1234(int M, vector<int> A) {
int N = A.size();
vector <int> C(M + 1, 0);
vector <int> vec[M + 1];
C[0] = A[0];
if (N == 1) {
answer(C, X, Y);
return ;
}
for (int i = 0; i < N; i++) {
vec[A[i]].push_back((i + 1 == N) ? 0 : A[i + 1]);
}
for (int i = 1; i <= M; i++) {
if (vec[i].empty()) continue;
if (vec[i].size() == 1) {
C[i] = vec[i][0];
continue;
}
int asd = 0;
while ((1 << asd) < vec[i].size()) {
asd++;
}
C[i] = -(sz + 1);
for (int j = 1; j < (1 << asd); j++) {
X.push_back(-(sz + j + j));
Y.push_back(-(sz + j + j + 1));
cnt[j + j] = 0;
cnt[j + j + 1] = 0;
if (j + j >= (1 << asd)) X.back() = -(sz + 1);
if (j + j + 1 >= (1 << asd)) Y.back() = -(sz + 1);
cnt[j] = 0;
}
for (int j = vec[i].size() - 1; j >= 0; j--) {
add(vec[i][j], 1, 0, (1 << asd) - 1);
}
sz += (1 << asd) - 1;
}
//for (int i = 0; i < X.size(); i++) {
//cout << X[i] << ' ' << Y[i] << '\n';
//}
//for (int to : C) {
//cout << to << ' ';
//}
//cout << endl;
answer(C, X, Y);
}
void create_circuit(int M, vector<int> A) {
if (M == 1) {
solve5(M, A);
} else {
solve1234(M, A);
}
}
/*
3 20
1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 3 3 3 3
4 2
1 2
3 5
1 2 1 2 2
*/
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'void solve1234(int, std::vector<int>)':
doll.cpp:80:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | while ((1 << asd) < vec[i].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... |