Submission #261149

#TimeUsernameProblemLanguageResultExecution timeMemory
261149Nightlight자동 인형 (IOI18_doll)C++14
12 / 100
59 ms9552 KiB
#include "doll.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;

int N, M;
int A[200005];
int tmp[200005];
int order[200005];
int to[200005];
int id[200005], pos[200005];
int X[200005], Y[200005];
int tot;
int cnt = 2;

void gen_order(int l, int r) {
  if(l == r) return void(pos[order[l]] = l);
  int mid = ((l + r) >> 1) + 1;
  for(int i = l; i <= r; i += 2) {
    tmp[l + (i - l) / 2] = order[i];
    tmp[mid + (i - l) / 2] = order[i + 1];
  }
  for(int i = l; i <= r; i++) order[i] = tmp[i];
  gen_order(l, mid - 1), gen_order(mid, r);
}

int DFS(int l, int r) {
  int now;
  if(l + 1 == r) {
    if(to[l] == to[r]) return to[l];
    if(l == 1 && r == tot) now = 1;
    else now = cnt++;
    X[now] = to[l], Y[now] = to[r];
//    cout << -now << " -> " << X[now] << " " << Y[now] << "\n";
    return -now;
  }
  int mid = (l + r) >> 1;
  int le = DFS(l, mid), ri = DFS(mid + 1, r);
  if(le == ri) return le;
  if(l == 1 && r == tot) now = 1;
  else now = cnt++;
  X[now] = le, Y[now] = ri;
//  cout << -now << " -> " << X[now] << " " << Y[now] << "\n";
  return -now;
}

void solve() {
  tot = log2(N);
//  cout << "tot -> " << tot << "\n";
  tot = (1 << tot);
  if(N > tot) tot <<= 1;
  for(int i = 1; i <= tot; i++) {
    order[i] = i;
  }
  gen_order(1, tot);
//  for(int i = 1; i <= tot; i++) cout << order[i] << " "; cout << "\n";
  memset(to, -1, sizeof(to));
  memset(tmp, -1, sizeof(tmp));
  for(int i = tot; i > tot - N; i--) tmp[order[i]] = 1;
  int p = 0;
  for(int i = 1; i <= tot; i++) {
    if(tmp[i] == -1) continue;
    to[pos[i]] = A[++p];
  }
  if(p > N) exit(1);
  assert(p == N);
  DFS(1, tot);
}

void create_circuit(int m, vector<int> a) {
  a.emplace_back(0);
  M = m, N = a.size();
  for(int i = 1; i <= N; i++) A[i] = a[i - 1];
  vector<int> c(M + 1);
  for(int i = 0; i <= M; i++) c[i] = -1;
  solve();
  vector<int> x(cnt - 1), y(cnt - 1);
  for(int i = 1; i < cnt; i++) {
    x[i - 1] = X[i];
//    assert(x[i - 1] <= m);
    y[i - 1] = Y[i];
//    assert(y[i - 1] <= m);
  }
  system("pause");
  answer(c, x, y);
}

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:84:9: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |   system("pause");
      |   ~~~~~~^~~~~~~~~
#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...