library

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

View the Project on GitHub sash2104/library

:heavy_check_mark: InitArrayクラスの簡易的なテスト
(test/marathon/initarray.test.cpp)

Depends on

Code

// @title InitArrayクラスの簡易的なテスト
// dummy problem
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A"
#include <cassert>
#include <iostream>
#include "../../util/marathon/initarray.hpp"
using namespace std;

static constexpr int n = 100;
void test() {
    InitArray<n> visited;
    for (int i = 0; i < n; ++i) {
        visited.reset();
        visited.set(i);
        for (int j = 0; j < n; ++j) {
            assert (visited[j] == (j==i));
        }
    }
}

int main() {
    test();

    // dummy output
    cout << "Hello World" << endl;
}
#line 1 "test/marathon/initarray.test.cpp"
// @title InitArrayクラスの簡易的なテスト
// dummy problem
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A"
#include <cassert>
#include <iostream>
#line 2 "util/marathon/initarray.hpp"
#include <array>

// 初期化をO(1)でできるやつ。BFSを繰り返すときに便利
// @see https://topcoder-tomerun.hatenablog.jp/entry/2022/11/06/145156
// @see https://twitter.com/koyumeishi_/status/1589142265209188352
template<int N>
struct InitArray {
  uint32_t epoch = 1;
  std::array<uint32_t, N> arr = {};
  void set(int i) { arr[i] = epoch; }
  void reset() { epoch++; }
  bool operator[](int i) const {
    return arr[i] == epoch;
  }
};
#line 7 "test/marathon/initarray.test.cpp"
using namespace std;

static constexpr int n = 100;
void test() {
    InitArray<n> visited;
    for (int i = 0; i < n; ++i) {
        visited.reset();
        visited.set(i);
        for (int j = 0; j < n; ++j) {
            assert (visited[j] == (j==i));
        }
    }
}

int main() {
    test();

    // dummy output
    cout << "Hello World" << endl;
}
Back to top page