結果
| 問題 |
No.555 世界史のレポート
|
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2021-06-23 00:29:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 2,000 ms |
| コード長 | 1,795 bytes |
| コンパイル時間 | 1,919 ms |
| コンパイル使用メモリ | 181,000 KB |
| 実行使用メモリ | 20,384 KB |
| 最終ジャッジ日時 | 2024-06-23 20:04:24 |
| 合計ジャッジ時間 | 3,733 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
/**
* @FileName a.cpp
* @Author kanpurin
* @Created 2021.06.23 00:29:21
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<typename T>
struct Dijkstra {
private:
int V;
struct edge { int to; T cost; };
vector<vector<edge>> G;
public:
const T inf = numeric_limits<T>::max();
vector<T> d;
Dijkstra() {}
Dijkstra(int V) : V(V) {
G.resize(V);
}
Dijkstra<T>& operator=(const Dijkstra<T>& obj) {
this->V = obj.V;
this->G = obj.G;
this->d = obj.d;
return *this;
}
void add_edge(int from, int to, T weight, bool directed = false) {
G[from].push_back({to,weight});
if (!directed) G[to].push_back({from,weight});
}
int add_vertex() {
G.push_back(vector<edge>());
return V++;
}
void build(int s) {
d.assign(V, inf);
typedef tuple<T, int> P;
priority_queue<P, vector<P>, greater<P>> pq;
d[s] = 0;
pq.push(P(d[s], s));
while (!pq.empty()) {
P p = pq.top(); pq.pop();
int v = get<1>(p);
if (d[v] < get<0>(p)) continue;
for (const edge &e : G[v])
{
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
pq.push(P(d[e.to], e.to));
}
}
}
}
};
int main() {
int n;cin >> n;
int c,v;cin >> c >> v;
Dijkstra<ll> g(n+1);
for (int i = 1; i <= n; i++) {
for (int j = 2; ; j++) {
g.add_edge(i,min(j*i,n),c+v*(j-1),true);
if (j*i >= n) break;
}
}
g.build(1);
cout << g.d[n] << endl;
return 0;
}
🍮かんプリン