結果

問題 No.1737 One to N
ユーザー Tannai Ryogo
提出日時 2022-07-16 01:05:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 726 bytes
コンパイル時間 1,826 ms
コンパイル使用メモリ 167,700 KB
実行使用メモリ 16,128 KB
最終ジャッジ日時 2024-06-27 23:19:31
合計ジャッジ時間 8,310 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
using LL = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const long long LINF = 1LL << 60;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); ++i)
template<class T>void chmin(T&a, T b){if(a > b) a = b;}
template<class T>void chmax(T&a, T b){if(a < b) a = b;}



int main(){
  //入力
  int N; cin >> N;
  //配列dpを定義(配列全体を無限大を表す値に初期化)
  vector<LL> dp(N+1, LINF);
  //初期条件
  dp[0] = 0;
  dp[1] = 0;

  //ループ
  for(int i = 2; i <= N; ++i){
    for(int j = 1; j < i; ++j){
     if(i%j==0) chmin(dp[i], dp[j]+(i/j));
    }
  }
 cout << dp[N] << endl; 
}
0