Submission #91635

# Submission time Handle Problem Language Result Execution time Memory
91635 2018-12-28T19:44:49 Z Swistakk Mechanical Doll (IOI18_doll) C++14
70.6719 / 100
187 ms 9124 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);
  vector<int> X, Y;
  A.PB(0);
  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;
      }
      assert(false);
    }
    int to_left = 1;
    while (2 * to_left < sz) {
      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 + 1) {
    outs *= 2;
    hei++;
  }
  Go(1, N + 1, 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;
      }
    }
  }
  
  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:70:11: warning: left operand of comma operator has no effect [-Wunused-value]
   70 |     debug(cur_node, sz, rem_hei);
      |           ^~~~~~~~
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:70:25: warning: right operand of comma operator has no effect [-Wunused-value]
   70 |     debug(cur_node, sz, rem_hei);
      |                         ^~~~~~~
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:110:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  110 |   debug(X);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:111:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  111 |   debug(Y);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:114:11: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  114 |     debug(goal);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:117:13: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  117 |       debug(cur_node);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:139:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  139 |   debug(X);
doll.cpp:26:21: note: in definition of macro 'debug'
   26 | #define debug(...) (__VA_ARGS__)
      |                     ^~~~~~~~~~~
doll.cpp:140:9: warning: statement has no effect [-Wunused-value]
   26 | #define debug(...) (__VA_ARGS__)
      |                    ~~~~~~~~~~~~~
......
  140 |   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:141:9: note: in expansion of macro 'st'
  141 |   debug(st);
      |         ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 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 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Output is partially correct
2 Correct 86 ms 5392 KB Output is correct
3 Partially correct 82 ms 5316 KB Output is partially correct
4 Partially correct 144 ms 8872 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Output is partially correct
2 Correct 86 ms 5392 KB Output is correct
3 Partially correct 82 ms 5316 KB Output is partially correct
4 Partially correct 144 ms 8872 KB Output is partially correct
5 Partially correct 144 ms 9124 KB Output is partially correct
6 Partially correct 187 ms 8984 KB Output is partially correct
7 Partially correct 144 ms 9012 KB Output is partially correct
8 Partially correct 141 ms 8952 KB Output is partially correct
9 Partially correct 97 ms 5436 KB Output is partially correct
10 Partially correct 145 ms 9012 KB Output is partially correct
11 Partially correct 140 ms 8888 KB Output is partially correct
12 Partially correct 86 ms 5440 KB Output is partially correct
13 Correct 90 ms 5608 KB Output is correct
14 Partially correct 91 ms 5640 KB Output is partially correct
15 Partially correct 91 ms 5700 KB Output is partially correct
16 Partially correct 4 ms 460 KB Output is partially correct
17 Correct 77 ms 5672 KB Output is correct
18 Correct 93 ms 5352 KB Output is correct
19 Partially correct 86 ms 5324 KB Output is partially correct
20 Partially correct 151 ms 8912 KB Output is partially correct
21 Partially correct 136 ms 8864 KB Output is partially correct
22 Partially correct 149 ms 8936 KB Output is partially correct