結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー ヒッキープログラミングするスレ GitHub ガチヒッキープログラミングするスレ GitHub ガチ
提出日時 2016-12-18 08:56:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,122 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 77,892 KB
実行使用メモリ 36,916 KB
最終ジャッジ日時 2023-08-21 00:36:38
合計ジャッジ時間 10,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,228 KB
testcase_01 AC 5 ms
9,180 KB
testcase_02 AC 6 ms
9,336 KB
testcase_03 AC 8 ms
9,352 KB
testcase_04 AC 8 ms
9,188 KB
testcase_05 AC 9 ms
9,276 KB
testcase_06 AC 7 ms
9,296 KB
testcase_07 AC 10 ms
9,228 KB
testcase_08 AC 8 ms
9,188 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 8 ms
9,128 KB
testcase_12 AC 11 ms
9,284 KB
testcase_13 AC 10 ms
9,236 KB
testcase_14 WA -
testcase_15 AC 14 ms
9,548 KB
testcase_16 WA -
testcase_17 AC 15 ms
9,504 KB
testcase_18 AC 13 ms
9,444 KB
testcase_19 AC 14 ms
9,444 KB
testcase_20 AC 12 ms
9,596 KB
testcase_21 WA -
testcase_22 AC 15 ms
9,444 KB
testcase_23 AC 13 ms
9,548 KB
testcase_24 AC 699 ms
36,748 KB
testcase_25 AC 708 ms
36,704 KB
testcase_26 WA -
testcase_27 AC 666 ms
36,704 KB
testcase_28 WA -
testcase_29 AC 702 ms
36,716 KB
testcase_30 AC 706 ms
36,688 KB
testcase_31 WA -
testcase_32 AC 671 ms
36,592 KB
testcase_33 AC 659 ms
36,812 KB
testcase_34 AC 162 ms
23,348 KB
testcase_35 AC 7 ms
9,352 KB
testcase_36 AC 5 ms
9,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

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

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

inline
long long ky(const int a, const int b) { return 100000LL*(long long)a + (long long)b; }

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[ky(a,b)] = c;
    }
    
    for (int i = 0; i < n; i++) c2[i] = 16000000LL;
    
    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[ky(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[ky(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