結果

問題 No.555 世界史のレポート
ユーザー たこしたこし
提出日時 2018-09-27 16:25:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 739 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 163,660 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 09:04:19
合計ジャッジ時間 7,543 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 11 ms
5,376 KB
testcase_08 AC 13 ms
5,376 KB
testcase_09 AC 14 ms
5,376 KB
testcase_10 AC 504 ms
5,376 KB
testcase_11 AC 566 ms
5,376 KB
testcase_12 AC 499 ms
5,376 KB
testcase_13 AC 435 ms
5,376 KB
testcase_14 AC 546 ms
5,376 KB
testcase_15 AC 560 ms
5,376 KB
testcase_16 AC 471 ms
5,376 KB
testcase_17 AC 524 ms
5,376 KB
testcase_18 AC 572 ms
5,376 KB
testcase_19 AC 739 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdio>
#include <string>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 50005;

int N, C, V;

int dp[MAX_N];
vector<int> prime;

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

  bool used[MAX_N];
  for(int i = 2; i < MAX_N; i++) {
    if(!used[i]) {
      prime.push_back(i);
      used[i] = true;
      for(int j = 2; i*j < MAX_N; j++) {
	used[i*j] = true;
      }
    }
  }

  fill(dp, dp+N+1, INF);

  dp[1] = 0;
  for(int i = 2; i <= N; i++) {
    dp[i] = min(dp[i], dp[1] + C + V*(i-1));
    for(int p : prime) {
      for(int j = 1; j*p <= sqrt(i); j++) {
	int k = p*j;
	if(i%k == 0) {
	  dp[i] = min(dp[i], dp[k] + C + V*(i/k-1));
	  k = i/k;
	  dp[i] = min(dp[i], dp[k] + C + V*(i/k-1));
	}
      }
    }
  }

  int ans = INF;

  for(int i = 1; i < N; i++) {
    int k = (N%i == 0 ? 1 : 0);
    int kk = N/i - k;
    if(kk == 0) {
      kk = 1;
    }
    ans = min(ans, dp[i] + C + V*kk);
    //cerr << i << " " << dp[i] << " " << ans << endl;
  }

  cout << min(ans, dp[N]) << endl;

  return 0;
}
0