結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー nebukuro09nebukuro09
提出日時 2016-12-18 15:27:17
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 154,196 KB
実行使用メモリ 32,652 KB
最終ジャッジ日時 2023-09-02 23:38:14
合計ジャッジ時間 8,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 275 ms
20,136 KB
testcase_25 AC 275 ms
20,040 KB
testcase_26 AC 276 ms
19,824 KB
testcase_27 AC 276 ms
20,868 KB
testcase_28 AC 276 ms
20,264 KB
testcase_29 AC 277 ms
19,732 KB
testcase_30 AC 278 ms
20,124 KB
testcase_31 AC 274 ms
20,308 KB
testcase_32 AC 274 ms
20,304 KB
testcase_33 AC 278 ms
21,200 KB
testcase_34 AC 98 ms
32,652 KB
testcase_35 AC 3 ms
4,384 KB
testcase_36 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


alias Tuple!(int, "e", int, "c") edge;
int N, M, a, b, c;
int[] earliest, latest;
edge[][] adj;
edge[][] inv;

int rec_back(int n) {
    if (earliest[n] > -1)
        return earliest[n];
    earliest[n] = inv[n].map!(to => rec_back(to.e)+to.c).reduce!(max);
    return earliest[n];
}

int rec_forward(int n) {
    if (latest[n] > -1)
        return latest[n];
    latest[n] = adj[n].map!(to => rec_forward(to.e)-to.c).reduce!(min);
    return latest[n];
}

void main() {
    scanf("%d %d", &N, &M);

    adj = new edge[][](N);
    inv = new edge[][](N);
    foreach (i; 0..M) {
        scanf("%d %d %d", &a, &b, &c);
        adj[a] ~= edge(b, c);
        inv[b] ~= edge(a, c);
    }

    earliest = new int[](N);
    earliest[0] = 0;
    foreach (i; 1..N) earliest[i] = -1;
    rec_back(N-1);

    latest = new int[](N);
    latest[N-1] = earliest[N-1];
    foreach (i; 0..N-1) latest[i] = -1;
    rec_forward(0);

    int ans = N.iota.map!(n => earliest[n] < latest[n]).sum;
    writefln("%d %d/%d", latest[N-1], ans, N);
}
0