結果

問題 No.555 世界史のレポート
ユーザー hiyokko2hiyokko2
提出日時 2017-09-08 11:29:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 157,668 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 19:57:51
合計ジャッジ時間 3,432 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 135 ms
5,376 KB
testcase_11 AC 160 ms
5,376 KB
testcase_12 AC 134 ms
5,376 KB
testcase_13 AC 109 ms
5,376 KB
testcase_14 AC 149 ms
5,376 KB
testcase_15 AC 151 ms
5,376 KB
testcase_16 AC 122 ms
5,376 KB
testcase_17 AC 144 ms
5,376 KB
testcase_18 AC 158 ms
5,376 KB
testcase_19 AC 226 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) for(ll i=1;i<=(n);i++)
#define MOD 1000000007
#define int long long
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1e9;

int N;  //N文字以上作る
int C;  //コピーコスト
int V;  //ペーストコスト

int dp[101010]; //i文字ちょうど作る最小コスト

signed main()
{
    cin >> N;
    cin >> C >> V;

    dp[1] = 0;
    int ans = LLONG_MAX / 3;
    for (int i=2; i<=2*N-2; i++) {
        dp[i] = LLONG_MAX / 3;
        for (int j=1; j*j<=i; j++) {
            if (i % j == 0) {
                //jがiの約数
                dp[i] = min(dp[i], dp[j] + C + V * (i / j - 1));
                //i/jがiの約数
                if (i / j != i) {
                    dp[i] = min(dp[i], dp[i/j] + C + V * (j - 1));
                }
            }
        }
        if (i >= N && ans > dp[i]) ans = dp[i];
    }

    cout << ans << endl;
}
0