This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: STANDALONE
#include <iostream>
#include <vector>
#include <array>
#include "tools/assert_that.hpp"
#include "tools/transposed.hpp"
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
assert_that(tools::transposed(std::vector<std::vector<int>> {
}) == std::vector<std::vector<int>> {
});
assert_that(tools::transposed(std::vector<std::vector<int>> {
{},
{},
}) == std::vector<std::vector<int>> {
});
assert_that(tools::transposed(std::vector<std::vector<int>> {
{1, 2, 3},
{4, 5, 6},
}) == std::vector<std::vector<int>> {
{1, 4},
{2, 5},
{3, 6},
});
assert_that(tools::transposed(std::array<std::vector<int>, 0> {{
}}) == std::vector<std::array<int, 0>> {
});
assert_that(tools::transposed(std::array<std::vector<int>, 2> {{
{},
{},
}}) == std::vector<std::array<int, 2>> {
});
assert_that(tools::transposed(std::array<std::vector<int>, 2> {{
{1, 2, 3},
{4, 5, 6},
}}) == std::vector<std::array<int, 2>> {
{1, 4},
{2, 5},
{3, 6},
});
assert_that(tools::transposed(std::vector<std::array<int, 0>> {
}) == std::array<std::vector<int>, 0> {{
}});
assert_that(tools::transposed(std::vector<std::array<int, 3>> {
}) == std::array<std::vector<int>, 3> {{
{},
{},
{},
}});
assert_that(tools::transposed(std::vector<std::array<int, 0>> {
{},
{},
}) == std::array<std::vector<int>, 0> {{
}});
assert_that(tools::transposed(std::vector<std::array<int, 3>> {
{1, 2, 3},
{4, 5, 6},
}) == std::array<std::vector<int>, 3> {{
{1, 4},
{2, 5},
{3, 6},
}});
assert_that(tools::transposed(std::array<std::array<int, 0>, 0> {{
}}) == std::array<std::array<int, 0>, 0> {{
}});
assert_that(tools::transposed(std::array<std::array<int, 3>, 0> {{
}}) == std::array<std::array<int, 0>, 3> {{
{},
{},
{},
}});
assert_that(tools::transposed(std::array<std::array<int, 0>, 2> {{
{},
{},
}}) == std::array<std::array<int, 2>, 0> {{
}});
assert_that(tools::transposed(std::array<std::array<int, 3>, 2> {{
{1, 2, 3},
{4, 5, 6},
}}) == std::array<std::array<int, 2>, 3> {{
{1, 4},
{2, 5},
{3, 6},
}});
return 0;
}
#line 1 "tests/transposed.test.cpp"
// competitive-verifier: STANDALONE
#include <iostream>
#include <vector>
#include <array>
#line 1 "tools/assert_that.hpp"
#line 5 "tools/assert_that.hpp"
#include <cstdlib>
#define assert_that_impl(cond, file, line, func) do {\
if (!cond) {\
::std::cerr << file << ':' << line << ": " << func << ": Assertion `" << #cond << "' failed." << '\n';\
::std::exit(EXIT_FAILURE);\
}\
} while (false)
#define assert_that(...) assert_that_impl((__VA_ARGS__), __FILE__, __LINE__, __func__)
#line 1 "tools/transposed.hpp"
#line 5 "tools/transposed.hpp"
#include <cassert>
#include <algorithm>
#include <cstddef>
#line 9 "tools/transposed.hpp"
namespace tools {
template <typename T>
::std::vector<::std::vector<T>> transposed(const ::std::vector<::std::vector<T>>& matrix) {
const auto N = matrix.size();
const auto M = matrix.empty() ? 0 : matrix.front().size();
assert(::std::all_of(matrix.begin(), matrix.end(), [&](const auto& row) { return row.size() == M; }));
auto res = ::std::vector(M, ::std::vector<T>(N));
for (::std::size_t r = 0; r < M; ++r) {
for (::std::size_t c = 0; c < N; ++c) {
res[r][c] = matrix[c][r];
}
}
return res;
}
template <typename T, ::std::size_t N>
::std::vector<::std::array<T, N>> transposed(const ::std::array<::std::vector<T>, N>& matrix) {
const auto M = matrix.empty() ? 0 : matrix.front().size();
assert(::std::all_of(matrix.begin(), matrix.end(), [&](const auto& row) { return row.size() == M; }));
auto res = ::std::vector(M, ::std::array<T, N>{});
for (::std::size_t r = 0; r < M; ++r) {
for (::std::size_t c = 0; c < N; ++c) {
res[r][c] = matrix[c][r];
}
}
return res;
}
template <typename T, ::std::size_t M>
::std::array<::std::vector<T>, M> transposed(const ::std::vector<::std::array<T, M>>& matrix) {
const auto N = matrix.size();
::std::array<::std::vector<T>, M> res;
for (::std::size_t r = 0; r < M; ++r) {
res[r].resize(N);
for (::std::size_t c = 0; c < N; ++c) {
res[r][c] = matrix[c][r];
}
}
return res;
}
template <typename T, ::std::size_t N, ::std::size_t M>
::std::array<::std::array<T, N>, M> transposed(const ::std::array<::std::array<T, M>, N>& matrix) {
::std::array<::std::array<T, N>, M> res;
for (::std::size_t r = 0; r < M; ++r) {
for (::std::size_t c = 0; c < N; ++c) {
res[r][c] = matrix[c][r];
}
}
return res;
}
}
#line 8 "tests/transposed.test.cpp"
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
assert_that(tools::transposed(std::vector<std::vector<int>> {
}) == std::vector<std::vector<int>> {
});
assert_that(tools::transposed(std::vector<std::vector<int>> {
{},
{},
}) == std::vector<std::vector<int>> {
});
assert_that(tools::transposed(std::vector<std::vector<int>> {
{1, 2, 3},
{4, 5, 6},
}) == std::vector<std::vector<int>> {
{1, 4},
{2, 5},
{3, 6},
});
assert_that(tools::transposed(std::array<std::vector<int>, 0> {{
}}) == std::vector<std::array<int, 0>> {
});
assert_that(tools::transposed(std::array<std::vector<int>, 2> {{
{},
{},
}}) == std::vector<std::array<int, 2>> {
});
assert_that(tools::transposed(std::array<std::vector<int>, 2> {{
{1, 2, 3},
{4, 5, 6},
}}) == std::vector<std::array<int, 2>> {
{1, 4},
{2, 5},
{3, 6},
});
assert_that(tools::transposed(std::vector<std::array<int, 0>> {
}) == std::array<std::vector<int>, 0> {{
}});
assert_that(tools::transposed(std::vector<std::array<int, 3>> {
}) == std::array<std::vector<int>, 3> {{
{},
{},
{},
}});
assert_that(tools::transposed(std::vector<std::array<int, 0>> {
{},
{},
}) == std::array<std::vector<int>, 0> {{
}});
assert_that(tools::transposed(std::vector<std::array<int, 3>> {
{1, 2, 3},
{4, 5, 6},
}) == std::array<std::vector<int>, 3> {{
{1, 4},
{2, 5},
{3, 6},
}});
assert_that(tools::transposed(std::array<std::array<int, 0>, 0> {{
}}) == std::array<std::array<int, 0>, 0> {{
}});
assert_that(tools::transposed(std::array<std::array<int, 3>, 0> {{
}}) == std::array<std::array<int, 0>, 3> {{
{},
{},
{},
}});
assert_that(tools::transposed(std::array<std::array<int, 0>, 2> {{
{},
{},
}}) == std::array<std::array<int, 2>, 0> {{
}});
assert_that(tools::transposed(std::array<std::array<int, 3>, 2> {{
{1, 2, 3},
{4, 5, 6},
}}) == std::array<std::array<int, 2>, 3> {{
{1, 4},
{2, 5},
{3, 6},
}});
return 0;
}