結果

問題 No.555 世界史のレポート
ユーザー たこしたこし
提出日時 2018-09-27 16:25:50
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 697 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 3,285 ms
コンパイル使用メモリ 148,072 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 09:38:10
合計ジャッジ時間 7,453 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 6 ms
4,376 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 472 ms
4,376 KB
testcase_11 AC 527 ms
4,376 KB
testcase_12 AC 468 ms
4,380 KB
testcase_13 AC 405 ms
4,380 KB
testcase_14 AC 514 ms
4,376 KB
testcase_15 AC 523 ms
4,380 KB
testcase_16 AC 443 ms
4,376 KB
testcase_17 AC 490 ms
4,376 KB
testcase_18 AC 536 ms
4,376 KB
testcase_19 AC 697 ms
4,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