이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
int get(vector<int> gider, int *X, int *Y, int *index){
/*cout << "get -> ";
for (int i = 0; i < gider.size(); i++) cout << gider[i] << " "; cout << endl;
*/
if (gider.size() == 0) return 0;
bool ayn = true;
for (int i = 1; i < (int)gider.size(); i++){
if (gider[i-1] != gider[i]){
ayn = false;
break;
}
}
if (ayn) return gider[0];
vector<int> gider1(gider.size()/2);
vector<int> gider2(gider.size()/2);
for (int i = 0; i < (int)gider.size(); i++){
if (i & 1){
gider2[i/2] = gider[i];
} else gider1[i/2] = gider[i];
}
//cout << "negative" << endl;
int sonind = *index;
int ret = -sonind-1;
(*index)++;
X[sonind] = get(gider1, X, Y, index);
Y[sonind] = get(gider2, X, Y, index);
return ret;
}
void create_circuit(int M, vector<int> A) {
//cout << "create_circuit(" << M << ");\n";
vector<int> C(M+1);
for (int i = 0; i < M+1; i++) C[i] = 0;
C[0] = A[0];
vector<int> gider[M+1];
for (int i = 1; i < (int)A.size(); i++){
gider[A[i-1]].push_back(A[i]);
}
int X[40000];
int Y[40000];
int index = 0;
for (int i = 1; i <= M; i++){
C[i] = get(gider[i], X, Y, &index);
}
vector<int> Xv(index);
vector<int> Yv(index);
for (int i = 0; i < index; i++){
Xv[i] = X[i];
Yv[i] = Y[i];
}
/*cout << "C: ";
for (int i = 0; i < C.size(); i++) cout << C[i] << " "; cout << endl;
cout << "X: ";
for (int i = 0; i < Xv.size(); i++) cout << Xv[i] << " "; cout << endl;
cout << "Y: ";
for (int i = 0; i < Yv.size(); i++) cout << Yv[i] << " "; cout << endl;
cout << "index: " << index << endl;
*/
answer(C, Xv, Yv);
}
/*void create_circuit(int M, vector<int> A){
cout << "create_circuit" << endl;
int N = A.size();
std::vector<int> C(M + 1);
C[0] = -1;
for (int i = 1; i <= M; ++i) {
C[i] = 1;
}
std::vector<int> X(N), Y(N);
for (int k = 0; k < N; ++k) {
X[k] = Y[k] = A[k];
}
answer(C, X, Y);
}*/
# | 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... |