답안 #91732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91732 2018-12-29T15:51:03 Z Swistakk 자동 인형 (IOI18_doll) C++14
100 / 100
209 ms 9320 KB
#include "doll.h"

#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }



void create_circuit(int M, std::vector<int> A) {
  int N = A.size();
  vector<int> C(M + 1, -1);
  C[0] = A[0];
  vector<int> X, Y;
  A.PB(0);
  A.erase(A.begin());
  function<int(int, int, int)> Go = [&](int cur_node, int sz, int rem_hei) {
    debug(cur_node, sz, rem_hei);
    if (sz == 0) { return 0; }
    if (rem_hei == 0) {
      if (sz == 2) {
        X.PB(0);
        Y.PB(0);
        return 1;
      }
      if (sz == 1) {
        X.PB(-1);
        Y.PB(0);
        return 1;
      }
      debug(sz);
      assert(false);
    }
    int to_left = min(sz, 1 << rem_hei);
//     while (2 * to_left <= min(sz, 1 << (rem_hei))) {
//       to_left *= 2;
//     }
    int to_right = sz - to_left;
    X.PB(-(cur_node + 1));
    Y.PB(0);
    int lsz = Go(cur_node + 1, to_left, rem_hei - 1);
    debug(SZ(Y), cur_node);
    Y[cur_node - 1] = -(cur_node + 1  + lsz);
    //return lsz + 
    int rsz = Go(cur_node + 1 + lsz, to_right, rem_hei - 1);
    if (rsz == 0) {
      Y[cur_node - 1] = -1;
      swap(X[cur_node - 1], Y[cur_node - 1]); 
    }
    return lsz + rsz + 1;
  };
  int hei = 0;
  int outs = 2;
  while (outs < N) {
    outs *= 2;
    hei++;
  }
  Go(1, N, hei);
  debug(X);
  debug(Y);
  VI st(2 * N + 5);
  for (auto goal : A) {
    debug(goal);
    int cur_node = 1;
    while (1) {
      debug(cur_node);
      int to = -1;
      if (st[cur_node] == 0) {
        to = -X[cur_node - 1];
      } else {
        to = -Y[cur_node - 1];
      }
      if (to == 0) {
        if (st[cur_node] == 0) {
          X[cur_node - 1] = goal;
        } else {
          Y[cur_node - 1] = goal;
        }
        st[cur_node] ^= 1;
        break;
      } else {
        st[cur_node] ^= 1;
        cur_node = to;
      }
    }
  }
  
  REP (i, SZ(X)) {
    debug(i + 1, -X[i], -Y[i]);
  }
  debug(X);
  debug(Y);
  debug(st);
  
  
  
  
  answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void _dbg(const char*, TH, TA ...)':
doll.cpp:20:3: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   20 |   while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
      |   ^~~~~
doll.cpp:20:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   20 |   while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
      |                                     ^~~~
doll.cpp: In lambda function:
doll.cpp:72:11: warning: left operand of comma operator has no effect [-Wunused-value]
   72 |     debug(cur_node, sz, rem_hei);
      |           ^~~~~~~~
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:72:25: warning: right operand of comma operator has no effect [-Wunused-value]
   72 |     debug(cur_node, sz, rem_hei);
      |                         ^~~~~~~
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:85:13: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
   85 |       debug(sz);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:113:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  113 |   debug(X);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:114:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  114 |   debug(Y);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:117:11: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  117 |     debug(goal);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:120:13: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  120 |       debug(cur_node);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:143:13: warning: left operand of comma operator has no effect [-Wunused-value]
  143 |     debug(i + 1, -X[i], -Y[i]);
      |           ~~^~~
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:143:18: warning: value computed is not used [-Wunused-value]
  143 |     debug(i + 1, -X[i], -Y[i]);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:145:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  145 |   debug(X);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:146:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  146 |   debug(Y);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:6:12: warning: statement has no effect [-Wunused-value]
    6 | #define st first
      |            ^
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:147:9: note: in expansion of macro 'st'
  147 |   debug(st);
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 50 ms 4032 KB Output is correct
3 Correct 48 ms 3864 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 13 ms 1356 KB Output is correct
6 Correct 67 ms 5436 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 50 ms 4032 KB Output is correct
3 Correct 48 ms 3864 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 13 ms 1356 KB Output is correct
6 Correct 67 ms 5436 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 91 ms 6272 KB Output is correct
9 Correct 93 ms 6508 KB Output is correct
10 Correct 142 ms 9320 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 50 ms 4032 KB Output is correct
3 Correct 48 ms 3864 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 13 ms 1356 KB Output is correct
6 Correct 67 ms 5436 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 91 ms 6272 KB Output is correct
9 Correct 93 ms 6508 KB Output is correct
10 Correct 142 ms 9320 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 141 ms 8868 KB Output is correct
15 Correct 99 ms 5828 KB Output is correct
16 Correct 148 ms 8604 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 209 ms 8984 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 70 ms 5740 KB Output is correct
3 Correct 78 ms 5380 KB Output is correct
4 Correct 144 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 70 ms 5740 KB Output is correct
3 Correct 78 ms 5380 KB Output is correct
4 Correct 144 ms 8024 KB Output is correct
5 Correct 134 ms 8568 KB Output is correct
6 Correct 132 ms 8472 KB Output is correct
7 Correct 148 ms 8352 KB Output is correct
8 Correct 150 ms 8204 KB Output is correct
9 Correct 99 ms 5328 KB Output is correct
10 Correct 137 ms 8184 KB Output is correct
11 Correct 131 ms 8120 KB Output is correct
12 Correct 86 ms 5320 KB Output is correct
13 Correct 75 ms 5936 KB Output is correct
14 Correct 88 ms 5580 KB Output is correct
15 Correct 94 ms 5740 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 76 ms 5652 KB Output is correct
18 Correct 78 ms 5696 KB Output is correct
19 Correct 81 ms 5384 KB Output is correct
20 Correct 122 ms 8172 KB Output is correct
21 Correct 139 ms 8040 KB Output is correct
22 Correct 133 ms 8104 KB Output is correct