結果
問題 |
No.370 道路の掃除
|
ユーザー |
|
提出日時 | 2016-05-14 00:05:07 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,148 bytes |
コンパイル時間 | 1,668 ms |
コンパイル使用メモリ | 168,952 KB |
実行使用メモリ | 814,480 KB |
最終ジャッジ日時 | 2024-10-05 18:49:50 |
合計ジャッジ時間 | 9,273 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 10 MLE * 4 -- * 7 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 100000000; int tmp; struct G { int count; int now; int dis; vector<int> memo; G(int count, int now, int dis, vector<int> memo) : count(count), now(now), dis(dis), memo(memo) {} bool operator>(const G &g) const { return dis > g.dis; //else return count > g.count; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> d(m + 1, 0), minc(n + 1, INF); for (int i = 1; i <= m; i++) cin >> d[i]; priority_queue<G, vector<G>, greater<G> > pq; pq.push(G(0, 0, 0, vector<int>(m + 1, 0))); while (!pq.empty()) { G g = pq.top(); pq.pop(); if (g.count > n) break; g.memo[g.now] = 1; minc[g.count] = min(minc[g.count], g.dis); for (int i = 1; i <= m; i++) { if (g.memo[i]) continue; if (minc[g.count + 1] == INF) { pq.push(G(g.count + 1, i, g.dis + abs(d[i] - d[g.now]), g.memo)); } } } cout << minc[n] << "\n"; return 0; }