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>
#define MAX 1000000000
using namespace std;
typedef vector<int> vi;
vector<vi> swi;
int usd[100010];
void create_circuit(int M, std::vector<int> A) {
map<int,int> m;
for(int i=0;i<A.size();i++){
m[A[i]]++;
}
int siz=0;
for(int i=1;i<=M;i++){
if(m[i]==2) siz++;
if(m[i]==3 or m[i]==4) siz+=3;
}
vector<int>C,X,Y;
swi.resize(M+1);
C.resize(M+1);
X.assign(siz+1,-MAX);
Y.assign(siz+1,-MAX);
int sw=-1;
for(int i=1;i<=M;i++){
if(m[i]==2){
swi[i].push_back(sw);
sw--;
}
if(m[i]==3 or m[i]==4){
swi[i].push_back(sw);
sw--;
swi[i].push_back(sw);
sw--;
swi[i].push_back(sw);
sw--;
}
}
for(int i=1;i<=M;i++){
if(swi[i].size()==3){
int si=swi[i][0],s2=swi[i][2];
X[abs(si)]=swi[i][1];
Y[abs(si)]=swi[i][2];
if(m[i]==3){
Y[abs(s2)]=si;
}
}
}
A.push_back(MAX);
C[0]=A[0];
for(int i=0;i<A.size()-1;i++){
usd[A[i]]++;
if(m[A[i]]==1){
C[A[i]]=A[i+1];
}
if(m[A[i]]==2){
int si=swi[A[i]][0];
C[A[i]]=si;;
if(X[abs(si)]==-MAX){
X[abs(si)]=A[i+1];
}
else{
Y[abs(si)]=A[i+1];
}
}
if(m[A[i]]==4 or m[A[i]]==3){
int si=swi[A[i]][0],s1=swi[A[i]][1],s2=swi[A[i]][2];
C[A[i]]=si;
if(usd[A[i]]%2!=0){
if(X[abs(s1)]==-MAX)
X[abs(s1)]=A[i+1];
else Y[abs(s1)]=A[i+1];
}
else{
if(X[abs(s2)]==-MAX){
X[abs(s2)]=A[i+1];
}
else Y[abs(s2)]=A[i+1];
}
}
}
bool c0=0;
for(int i=1;i<=M;i++){
if(C[i]==MAX){
c0=1;
C[i]=0; break;
}
}
for(int i=0;i<X.size();i++){
if(c0==1) break;
if(X[i]==MAX){
c0=1;
X[i]=0;
}
if(Y[i]==MAX){
c0=1;
Y[i]=0;
}
}/*
for(int i=0;i<C.size();i++){
cout<<C[i]<<" ";
}
cout<<endl;
for(int j=0;j<X.size();j++){
cout<<X[j]<<" "<<Y[j]<<endl;
}*/
vector<int>XX,YY;
for(int i=1;i<X.size();i++) XX.push_back(X[i]);
for(int i=1;i<Y.size();i++) YY.push_back(Y[i]);
answer(C, XX, YY);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:10:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0;i<A.size();i++){
| ~^~~~~~~~~
doll.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<A.size()-1;i++){
| ~^~~~~~~~~~~
doll.cpp:88:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i=0;i<X.size();i++){
| ~^~~~~~~~~
doll.cpp:107:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for(int i=1;i<X.size();i++) XX.push_back(X[i]);
| ~^~~~~~~~~
doll.cpp:108:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for(int i=1;i<Y.size();i++) YY.push_back(Y[i]);
| ~^~~~~~~~~
# | 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... |