답안 #299422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299422 2020-09-14T21:46:29 Z DanerZein 자동 인형 (IOI18_doll) C++14
53 / 100
334 ms 17520 KB
#include "doll.h"
#include <bits/stdc++.h>
#define MAX 1000000000
using namespace std;
typedef vector<int> vi;
int vis[400010],G[400010];
vi X,Y,C;
int sw=0;
map<int,int> m;
void create_switch(int x){
  int ns=2;
  queue<int> q;
  sw--;
  int insw=sw;
  q.push(sw);
  C[x]=insw;
  int aux=m[x];
  while(ns<aux){
    // cout<<ns<<endl;
    int t=q.size();
    for(int i=0;i<t;i++){
      ns-=2;
      int y=q.front();
      q.pop();
      X.push_back(sw-1);
      Y.push_back(sw-2);
      q.push(sw-1);
      q.push(sw-2);
      ns+=4;
      sw-=2;
    }
  }
  while(!q.empty()){
    int y=q.front();
    q.pop();
    if(ns>aux){
      X.push_back(insw); ns--;
      Y.push_back(-MAX);
      G[abs(y)]=-1;
    }
    else{
      X.push_back(-MAX);
      Y.push_back(-MAX);
    }
  }
}
bool sa=0;
int dfs(int u){
  u=abs(u);
  /*if(sw==-6)
    cout<<u<<" "<<X[abs(u)-1]<<" "<<Y[abs(u)-1]<<" "<<G[u]<<" "<<X.size()<<endl;*/
  if(G[u]==-1){
    G[u]=1;
    return dfs(abs(X[abs(u)-1]));
  }
  if(G[u]==1){
    G[u]=0;
    if(Y[abs(u)-1]==-MAX){
      sa=1; return abs(u)-1;
    }
    return dfs(Y[abs(u)-1]);
  }
  else{
    G[u]=1;
    if(X[abs(u)-1]==-MAX){sa=0; return abs(u)-1;}
    return dfs(X[abs(u)-1]);
  }
}
void create_circuit(int M, std::vector<int> A) {

  for(int i=0;i<A.size();i++){
    m[A[i]]++;
  }
  A.push_back(0);
  memset(vis,0,sizeof vis);
  memset(G,0,sizeof G);
  C.resize(M+1);
  C[0]=A[0];
  for(int i=0;i<A.size()-1;i++){
    if(m[A[i]]!=1){
      if(!vis[A[i]]){
	//cout<<A[i]<<endl;
	create_switch(A[i]);
	int ids=dfs(abs(C[A[i]]));
	if(sa==0) X[ids]=A[i+1];
	else Y[ids]=A[i+1];
	vis[A[i]]=1;
	//cout<<ids<<endl;
      }
      else{
	sa=0;
	int ids=dfs(abs(C[A[i]]));
	if(sa==0) X[ids]=A[i+1];
	else Y[ids]=A[i+1];
	//cout<<ids<<endl;
      }
      /*for(int i=0;i<=abs(sw);i++){
	cout<<G[i]<<" ";
      }
      cout<<endl;*/
      /* cout<<X.size()<<endl;*/
    }
    else{
      C[A[i]]=A[i+1];
    }
  }
  /* for(int i=0;i<C.size();i++){
    cout<<C[i]<<" ";
  }
  cout<<endl;
  cout<<X.size()<<" "<<Y.size()<<endl;*/
  /*for(int i=0;i<X.size();i++) cout<<X[i]<<" ";
  cout<<endl;
  for(int j=0;j<Y.size();j++) cout<<Y[j]<<" ";
  cout<<endl;*/
  answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_switch(int)':
doll.cpp:23:11: warning: unused variable 'y' [-Wunused-variable]
   23 |       int y=q.front();
      |           ^
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for(int i=0;i<A.size();i++){
      |               ~^~~~~~~~~
doll.cpp:79:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int i=0;i<A.size()-1;i++){
      |               ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 64 ms 8076 KB Output is correct
3 Correct 59 ms 7868 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 13 ms 4556 KB Output is correct
6 Correct 115 ms 10152 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 64 ms 8076 KB Output is correct
3 Correct 59 ms 7868 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 13 ms 4556 KB Output is correct
6 Correct 115 ms 10152 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 130 ms 10556 KB Output is correct
9 Correct 176 ms 11324 KB Output is correct
10 Correct 265 ms 14748 KB Output is correct
11 Correct 3 ms 3424 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 64 ms 8076 KB Output is correct
3 Correct 59 ms 7868 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 13 ms 4556 KB Output is correct
6 Correct 115 ms 10152 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 130 ms 10556 KB Output is correct
9 Correct 176 ms 11324 KB Output is correct
10 Correct 265 ms 14748 KB Output is correct
11 Correct 3 ms 3424 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 334 ms 16100 KB Output is correct
15 Correct 156 ms 9788 KB Output is correct
16 Correct 234 ms 13044 KB Output is correct
17 Correct 4 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 4 ms 3404 KB Output is correct
20 Correct 287 ms 14780 KB Output is correct
21 Correct 3 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 3 ms 3404 KB Output is partially correct
2 Correct 71 ms 8648 KB Output is correct
3 Partially correct 141 ms 11296 KB Output is partially correct
4 Partially correct 168 ms 11852 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 3 ms 3404 KB Output is partially correct
2 Correct 71 ms 8648 KB Output is correct
3 Partially correct 141 ms 11296 KB Output is partially correct
4 Partially correct 168 ms 11852 KB Output is partially correct
5 Partially correct 287 ms 16196 KB Output is partially correct
6 Partially correct 223 ms 16876 KB Output is partially correct
7 Partially correct 210 ms 16612 KB Output is partially correct
8 Partially correct 230 ms 17248 KB Output is partially correct
9 Partially correct 149 ms 11956 KB Output is partially correct
10 Partially correct 227 ms 17520 KB Output is partially correct
11 Partially correct 219 ms 17516 KB Output is partially correct
12 Partially correct 118 ms 12228 KB Output is partially correct
13 Partially correct 123 ms 11264 KB Output is partially correct
14 Partially correct 146 ms 11176 KB Output is partially correct
15 Partially correct 129 ms 11028 KB Output is partially correct
16 Partially correct 5 ms 3660 KB Output is partially correct
17 Partially correct 114 ms 9768 KB Output is partially correct
18 Partially correct 119 ms 10640 KB Output is partially correct
19 Partially correct 125 ms 10248 KB Output is partially correct
20 Partially correct 188 ms 13464 KB Output is partially correct
21 Partially correct 199 ms 15624 KB Output is partially correct
22 Partially correct 146 ms 12872 KB Output is partially correct