結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー ヒッキープログラミングするスレ GitHub ガチヒッキープログラミングするスレ GitHub ガチ
提出日時 2016-12-18 08:39:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,998 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 80,312 KB
実行使用メモリ 36,112 KB
最終ジャッジ日時 2023-08-21 00:35:52
合計ジャッジ時間 10,716 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,976 KB
testcase_01 AC 5 ms
8,988 KB
testcase_02 AC 6 ms
8,984 KB
testcase_03 AC 10 ms
9,288 KB
testcase_04 AC 9 ms
8,972 KB
testcase_05 AC 14 ms
8,972 KB
testcase_06 AC 8 ms
8,984 KB
testcase_07 AC 15 ms
8,988 KB
testcase_08 AC 10 ms
8,936 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 11 ms
8,984 KB
testcase_12 AC 17 ms
8,988 KB
testcase_13 AC 13 ms
8,976 KB
testcase_14 WA -
testcase_15 AC 20 ms
9,200 KB
testcase_16 WA -
testcase_17 AC 21 ms
9,188 KB
testcase_18 AC 17 ms
9,192 KB
testcase_19 AC 20 ms
9,260 KB
testcase_20 AC 15 ms
9,380 KB
testcase_21 WA -
testcase_22 AC 22 ms
9,240 KB
testcase_23 AC 17 ms
9,236 KB
testcase_24 AC 733 ms
35,972 KB
testcase_25 AC 748 ms
36,004 KB
testcase_26 WA -
testcase_27 AC 719 ms
36,092 KB
testcase_28 WA -
testcase_29 AC 768 ms
35,956 KB
testcase_30 AC 763 ms
35,916 KB
testcase_31 WA -
testcase_32 AC 738 ms
35,828 KB
testcase_33 AC 737 ms
35,860 KB
testcase_34 AC 171 ms
22,724 KB
testcase_35 AC 8 ms
9,040 KB
testcase_36 AC 6 ms
9,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <map>

using namespace std;

typedef tuple<int, int> itup;
typedef map<itup, int> cmap;
typedef vector<int> ivec;

cmap cost;
ivec r[100000], s[100000], buf1(100000), buf2(100000), *tmp1 = &buf1, *tmp2 = &buf2, *tmp3;
unsigned t1[100000], c1[100000], t2[100000], c2[100000];

int main() {
    int n, m;
    cin >> n >> m;
    
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        r[a].push_back(b);
        s[b].push_back(a);
        cost[{a, b}] = c;
    }
    
    for (int i = 0; i < n; i++) c2[i] = 16000000;
    
    tmp1->push_back(0);
    while (tmp1->size()) {
        tmp2->clear();
        for (auto it=tmp1->begin();it!=tmp1->end();it++) {
            auto a=*it;
            auto ca=c1[a];
            auto hnd=&r[a];
            for (auto bp=hnd->begin();bp!=hnd->end();bp++) {
                auto b=*bp;
                c1[b] = max(c1[b], ca + cost[{a,b}]);
                t1[b]++;
                if (t1[b] == s[b].size()) tmp2->push_back(b);
            }
        }
        
        tmp3=tmp1;tmp1=tmp2;tmp2=tmp3;
    }
    
    c2[n - 1] = c1[n - 1];
    tmp1->clear();
    tmp1->push_back(n - 1);
    while (tmp1->size()) {
        tmp2->clear();
        for (auto it=tmp1->begin();it!=tmp1->end();it++) {
            auto b=*it;
            auto cb=c2[b];
            auto hnd=&s[b];
            for (auto ap=hnd->begin();ap!=hnd->end();ap++) {
                auto a=*ap;
                c2[a] = min(c2[a], cb - cost[{a,b}]);
                t2[a]++;
                if (t2[a] == r[a].size()) tmp2->push_back(a);
            }
        }
        
        tmp3=tmp1;tmp1=tmp2;tmp2=tmp3;
    }
    
    int p = 0;
    for (int i = 0; i < n; i++) {
        if (c1[i] != c2[i]) p++;
    }
    
    cout << c1[n - 1] << ' ' << p << '/' << n << endl;
    
    // for(int i = 0; i < n; i++)cout << i << ':' << c1[i] << ',' << c2[i] << endl;
    
    return 0;
}
0