cpp_library

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

View the Project on GitHub toyama1710/cpp_library

:heavy_check_mark: test/aoj/0407.test.cpp

Depends on

Code

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0407"

#include <algorithm>
#include <iostream>

#include "../../util/make_vector.hpp"

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    i64 n;
    cin >> n;
    auto v = make_vector({u64(n)}, 0ll);
    for (auto &vs : v) cin >> vs;

    i64 ans = 1ll << 60;
    rep(t, 2000 + 1) {
        i64 tmp = 0;
        rep(i, n) tmp = max(tmp, abs(t - v[i]));
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}
#line 1 "test/aoj/0407.test.cpp"
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0407"

#include <algorithm>
#include <iostream>

#line 1 "util/make_vector.hpp"



#include <cassert>
#include <cstdint>
#include <vector>

template <class T, uint64_t N>
auto make_vector_(const uint64_t *dim, T e) {
    if constexpr (N == 1) {
        return std::vector<T>(*dim, e);
    } else {
        auto v = make_vector_<T, N - 1>(dim + 1, e);
        return std::vector<decltype(v)>(*dim, v);
    }
};
template <class T, uint64_t N>
auto make_vector(const uint64_t (&dim)[N], const T &e) {
    assert(N > 0);
    return make_vector_<T, N>(dim, e);
};


#line 7 "test/aoj/0407.test.cpp"

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    i64 n;
    cin >> n;
    auto v = make_vector({u64(n)}, 0ll);
    for (auto &vs : v) cin >> vs;

    i64 ans = 1ll << 60;
    rep(t, 2000 + 1) {
        i64 tmp = 0;
        rep(i, n) tmp = max(tmp, abs(t - v[i]));
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}
Back to top page