結果

問題 No.370 道路の掃除
ユーザー finefine
提出日時 2016-05-14 00:05:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,148 bytes
コンパイル時間 1,924 ms
コンパイル使用メモリ 168,088 KB
実行使用メモリ 814,464 KB
最終ジャッジ日時 2024-04-15 17:35:08
合計ジャッジ時間 9,971 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 TLE -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 178 ms
117,492 KB
testcase_26 MLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0