結果
| 問題 | 
                            No.1 道のショートカット
                             | 
                    
| コンテスト | |
| ユーザー | 
                             codershifth
                         | 
                    
| 提出日時 | 2016-08-11 00:45:13 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 5 ms / 5,000 ms | 
| コード長 | 1,830 bytes | 
| コンパイル時間 | 757 ms | 
| コンパイル使用メモリ | 113,668 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-12 03:39:42 | 
| 合計ジャッジ時間 | 1,863 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 40 | 
ソースコード
import std.stdio;
import std.string;
import std.array;
import std.typecons;
import std.typetuple;
import std.container;
import std.algorithm;
import std.conv;
import std.math;
import std.format;
alias TypeTuple tie;
void mdaFill(T,S)(ref T[] arry, S val)
{
    import std.traits;
    static if (isIterable!(T))
    {
        foreach(ref a; arry)
            mdaFill(a, val);
    }
    else
    {
        import std.algorithm;
        fill(arry, val);
    }
}
void readlnToken(T...)(auto ref T args)
{
    import std.stdio;
    import std.conv;
    import std.string;
    import std.array;
    auto line = split(readln().strip);
    foreach(ref arg; args)
    {
        arg = to!(typeof(arg))(line[0]);
        line = line[1..$];
    }
    assert(line.empty()); // got all token??
}
void solve()
{
    int N,C,V;
    readlnToken(N);
    readlnToken(C);
    readlnToken(V);
    auto S = readln.strip.split.array.map!(to!int).map!(x => x-1);
    auto T = readln.strip.split.array.map!(to!int).map!(x => x-1);
    auto Y = readln.strip.split.array.map!(to!int);
    auto M = readln.strip.split.array.map!(to!int);
    alias Edge = Tuple!(int,"to",int,"cost",int,"time");
    auto edges = new Edge[][](N,0);
    foreach(i;0..V)
    {
        edges[S[i]] ~= Edge(T[i],Y[i],M[i]);
    }
    auto dp = new int[][](N,C+1);
    const inf = 1<<30;
    mdaFill(dp, inf);
    dp[0][0] = 0;
    foreach(i;0..N)
    {
        foreach(j;0..C)
        {
            foreach(e;edges[i])
            {
                if ( j+e.cost <= C )
                    dp[e.to][j+e.cost] = min(dp[e.to][j+e.cost], dp[i][j] + e.time);
            }
        }
    }
    int ret = inf;
    foreach(c;0..C+1)
        ret = min(ret, dp[N-1][c]);
    if (ret == inf)
        writeln(-1);
    else
        writeln(ret);
}
void main()
{
       solve();
}
            
            
            
        
            
codershifth