This documentation is automatically generated by competitive-verifier/competitive-verifier
入出力・宣言を簡潔に行える $2$ 次元配列.
matrix()
:$0$ 行 $0$ 列の $2$ 次元配列を作る.matrix(h, w)
:h
行 w
列の $2$ 次元配列を作る.matrix(h, w, init)
:init
を初期値とする h
行 w
列の $2$ 次元配列を作る.matrix(m_init)
:m_init
を初期値とする $2$ 次元配列を作る.assign(h, w)
:h
行 w
列の $2$ 次元配列を作る.assign(h, w, init)
:init
を初期値とする h
行 w
列の $2$ 次元配列を作る.size()
:配列の縦のサイズを返す.in()
:現在の要素サイズ分だけ標準入力する.in(h, w)
:h
行 w
列の $2$ 次元配列を作り標準入力する.out()
:要素を空白区切りで標準出力する.operator[](idx)
:idx
番目の要素である $1$ 次元配列の参照を返す.vector
を用いた多次元配列と同様に扱える.rangeout(x ,y)
:x
行 y
列目の要素が存在しない場合は true
,存在する場合は false
を返す.$H$ 行 $W$ 列の行列を扱うとする.
assign()
:$O(HW)$size()
:$O(1)$in()
:$O(HW)$out()
:$O(HW)$operator[](idx)
:$O(1)$rangeout(x, y)
:$O(1)$#pragma once
#ifndef call_include
#define call_include
#include <bits/stdc++.h>
using namespace std;
#endif
template<typename T> struct v2d {
private:
vector<vector<T>> m;
public:
v2d() {}
v2d(int h, int w) : m(h, vector<T>(w)) {}
v2d(int h, int w, const T &init) : m(h, vector<T>(w, init)) {}
v2d(const initializer_list<initializer_list<T>> m_init) : m(m_init.begin(), m_init.end()) {}
void assign(int h, int w) {
m.assign(h, vector<T>(w));
}
void assign(int h, int w, const T init) {
m.assign(h, vector<T>(w, init));
}
inline int size() const {
return m.size();
}
void in() {
for(vector<T> &v : m)
for(T &val : v) cin >> val;
}
void in(int h, int w) {
m.resize(h, vector<T>(w));
in();
}
void out() {
int h = m.size();
for(vector<T> &v : m) {
int sz = v.size();
for(int j = 0; j < sz; j++) {
cout << v[j] << (j == sz - 1 ? '\n' : ' ');
}
}
cout << flush;
}
inline vector<T> &operator[](int idx) {
assert(0 <= idx && idx < m.size());
return m[idx];
}
bool rangeout(int x, int y) {
if(x < 0 || y < 0 || x >= size() || y >= m[x].size()) return true;
return false;
}
};
#line 2 "structure/2d_array.cpp"
#ifndef call_include
#define call_include
#include <bits/stdc++.h>
using namespace std;
#endif
template<typename T> struct v2d {
private:
vector<vector<T>> m;
public:
v2d() {}
v2d(int h, int w) : m(h, vector<T>(w)) {}
v2d(int h, int w, const T &init) : m(h, vector<T>(w, init)) {}
v2d(const initializer_list<initializer_list<T>> m_init) : m(m_init.begin(), m_init.end()) {}
void assign(int h, int w) {
m.assign(h, vector<T>(w));
}
void assign(int h, int w, const T init) {
m.assign(h, vector<T>(w, init));
}
inline int size() const {
return m.size();
}
void in() {
for(vector<T> &v : m)
for(T &val : v) cin >> val;
}
void in(int h, int w) {
m.resize(h, vector<T>(w));
in();
}
void out() {
int h = m.size();
for(vector<T> &v : m) {
int sz = v.size();
for(int j = 0; j < sz; j++) {
cout << v[j] << (j == sz - 1 ? '\n' : ' ');
}
}
cout << flush;
}
inline vector<T> &operator[](int idx) {
assert(0 <= idx && idx < m.size());
return m[idx];
}
bool rangeout(int x, int y) {
if(x < 0 || y < 0 || x >= size() || y >= m[x].size()) return true;
return false;
}
};