제출 #623903

#제출 시각아이디문제언어결과실행 시간메모리
623903TimDeeMechanical Doll (IOI18_doll)C++17
100 / 100
129 ms11296 KiB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

int n, maxsz, maxh;
vector<int> c,x,y,a,s;
int cnt=0;

void build(int i, int h) {
  if (h==maxh-1) {x[i]=1e9+7, y[i]=1e9+7; return;}
  if (cnt==maxsz-1) return;
  y[i]=-(++cnt+1);
  build(cnt,h+1);
  if (cnt==maxsz-1) return;
  x[i]=-(++cnt+1);
  build(cnt,h+1);
}

void create_circuit(int m, vector<int>A) {

  n=A.size();
  c.assign(m+1,-1); c[0]=A[0];
  for(int i=1; i<n; ++i) a.push_back(A[i]); a.push_back(0);
  int lg=0; int X=n; while (X>>=1) lg++;
  maxsz=n+lg;
  maxh=lg+1;
  x.assign(maxsz,-1);
  y.assign(maxsz,-1);
  s.assign(maxsz,0);
  build(0,0);

  int have=0;
  for(int i=0; i<maxsz; ++i) {
    if (x[i]==1e9+7) have+=2;
  }

  while (have-n) {
    int i=0;
    while (1) {
      if (s[i]) {
        s[i]^=1;
        if (y[i]==1e9+7) {
          y[i]=-1;
          break;
        }
        i=-y[i]-1;
      } else {
        s[i]^=1;
        if (x[i]==1e9+7) {
          x[i]=-1;
          break;
        }
        i=-x[i]-1;
      }
    }
    --have;
  }

  for (auto v:a) {
    int i=0;
    while (1) {
      //cout<<i<<"->"; int ok; cin>>ok;
      if (s[i]) {
        s[i]^=1;
        if (y[i]==1e9+7) {
          y[i]=v;
          break;
        }
        i=-y[i]-1;
      } else {
        s[i]^=1;
        if (x[i]==1e9+7) {
          x[i]=v;
          break;
        }
        i=-x[i]-1;
      }
    }
  }

  for(int i=0; i<maxsz; ++i) {
    //cout<<-i-1<<" -> ["<<x[i]<<','<<y[i]<<"]\n";
  }

  answer(c,x,y);

}

컴파일 시 표준 에러 (stderr) 메시지

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:23:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   23 |   for(int i=1; i<n; ++i) a.push_back(A[i]); a.push_back(0);
      |   ^~~
doll.cpp:23:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   23 |   for(int i=1; i<n; ++i) a.push_back(A[i]); a.push_back(0);
      |                                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...