結果

問題 No.555 世界史のレポート
ユーザー tubo28tubo28
提出日時 2017-08-11 22:51:59
言語 C++14
(gcc 10.1.0 + boost 1.73.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 4,958 Byte
コンパイル時間 1,242 ms
使用メモリ 8,944 KB
最終ジャッジ日時 2020-05-25 03:54:53

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
8,900 KB
testcase_01 AC 2 ms
8,944 KB
testcase_02 AC 2 ms
8,940 KB
testcase_03 AC 2 ms
6,896 KB
testcase_04 AC 2 ms
6,904 KB
testcase_05 AC 2 ms
8,896 KB
testcase_06 AC 2 ms
6,896 KB
testcase_07 AC 2 ms
8,944 KB
testcase_08 AC 2 ms
6,900 KB
testcase_09 AC 2 ms
8,944 KB
testcase_10 AC 6 ms
8,900 KB
testcase_11 AC 6 ms
6,896 KB
testcase_12 AC 6 ms
6,900 KB
testcase_13 AC 6 ms
8,944 KB
testcase_14 AC 6 ms
6,900 KB
testcase_15 AC 10 ms
8,896 KB
testcase_16 AC 5 ms
8,940 KB
testcase_17 AC 6 ms
8,944 KB
testcase_18 AC 6 ms
8,900 KB
testcase_19 AC 8 ms
8,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
#include <bits/stdc++.h>
using ll = long long;
#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __print__(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void __print__(std::ostream &os, const char *del, const char *tail, const Fst &fst,
               const Rst &... rst) {
    os << fst << del;
    __print__(os, del, tail, rst...);
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __print__(os, ", ", "\n", __VA_ARGS__);           \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#endif

template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, " ", "\n", fst, rst...);
}

template <typename iter>
void println_(iter bgn, iter end) {
    while (bgn != end) println(*bgn++);
}

template <typename iter>
void print_(iter bgn, iter end) {
    while (bgn != end) {
        std::cout << *bgn++;
        std::cout << (bgn == end ? "\n" : " ");
    }
}

int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
         std::ios::sync_with_stdio(0), 0);

template <typename T>
std::vector<T> ndarray(int n, T v) {
    return std::vector<T>(n, v);
}
template <typename... Args>
auto ndarray(int n, Args... args) {
    auto val = ndarray(args...);
    return std::vector<decltype(val)>(n, move(val));
}

template <typename T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, true : false;
}

template <typename T>
bool umin(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

using namespace std;

template <typename monoid>
struct segment_tree {
    using M = monoid;
    using T = typename M::value_type;

    std::size_t sz;
    std::vector<T> x;

    segment_tree(std::size_t n = 0) {
        sz = 1;
        while (sz < n) sz *= 2;
        x.assign(sz * 2, M::id());
        initialize();
    }

    template <typename iterator>
    segment_tree(iterator first, iterator last) {
        sz = 1;
        std::size_t n = std::distance(first, last);
        while (sz < n) sz *= 2;
        x.assign(sz * 2, M::id());
        std::copy(first, last, x.begin() + sz);
        initialize();
    }

    void fill(const T& val) {
        std::fill(x.begin() + sz, x.end(), val);
        initialize();
    }

    void initialize() {
        for (int i = (int)sz - 1; i >= 1; --i) {
            x[i] = M::op(x[i * 2 + 0], x[i * 2 + 1]);
        }
    }

    T accumulate(std::size_t l, std::size_t r) const {
        T al = M::id(), ar = M::id();
        for (l += sz, r += sz; l < r; l /= 2, r /= 2) {
            if (l & 1) al = M::op(al, x[l++]);
            if (r & 1) ar = M::op(x[--r], ar);
        }
        return M::op(al, ar);
    }

    void update(std::size_t i, const T &val) {
        x[i += sz] = val;
        while (i > 1) {
            x[i / 2] = M::op(x[i], x[i ^ 1]);
            i /= 2;
        }
    }

    T operator[](std::size_t i) const { return x[sz + i]; }
};

template <typename T>
struct min_monoid {
    using value_type = T;
    static constexpr T id() { return std::numeric_limits<T>::max(); }
    static T op(const T &a, const T &b) { return std::min(a, b); }
};

template <typename T>
struct max_monoid {
    using value_type = T;
    static constexpr value_type id() { return std::numeric_limits<value_type>::min(); }
    static value_type op(const value_type &a, const value_type &b) { return std::max(a, b); }
};

template <typename T>
struct sum_monoid {
    using value_type = T;
    static constexpr value_type id() { return 0; }
    static value_type op(const value_type &a, const value_type &b) { return (a + b) % MOD; }
};

template <typename value_type>
using rmq = segment_tree<min_monoid<value_type>>;

template <typename value_type>
using rsq = segment_tree<sum_monoid<value_type>>;

const int INF = 1e9;

signed main() {
    int n;
    int c, v;
    while (cin >> n >> c >> v) {
        vector<ll> dp(n * 4 + 1, INF);
        dp[1] = 0;
        for (int i = 1; i <= n * 4; ++i) {
            for (int j = 1; i + i*j <= n * 4; ++j) {
                umin(dp[i + i*j], dp[i] + c + v*j);
            }
            // print_(all(dp));
        }
        print(*min_element(dp.begin() + n, dp.end()));
    }
}
0