library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub maspypy/library

:heavy_check_mark: seq/famous/gray_code.hpp

Verified with

Code

// 0, ..., 2^{LOG}-1 の順列であって、1 bit ずつ変化するものを返す

vc<int> gray_code(int LOG) {
  vc<int> res(1 << LOG);
  FOR(v, 1 << LOG) res[v] = v ^ (v >> 1);
  return res;
}
#line 1 "seq/famous/gray_code.hpp"
// 0, ..., 2^{LOG}-1 の順列であって、1 bit ずつ変化するものを返す

vc<int> gray_code(int LOG) {
  vc<int> res(1 << LOG);
  FOR(v, 1 << LOG) res[v] = v ^ (v >> 1);
  return res;
}
Back to top page