京都大学プログラミングコンテスト2015

Submission #533248

Source codeソースコード

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int kInf = 1 << 28;

int main()
{
    int t;
    cin >> t;
    while (--t >= 0) {
        int n;
        cin >> n;
        vector<vector<int>> a(n, vector<int>(n));
        for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            if (a[i][j] == -1) a[i][j] = kInf;
        }
        vector<vector<int>> b(a);
        for (int i = 0; i < n; i++) {
            b[i][i] = 0;
        }
        for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            b[i][j] = min(b[i][j], b[i][k] + b[k][j]);
        }
        bool flag = true;
        for (int i = 0; flag && i < n; i++)
        for (int j = 0; flag && j < n; j++) {
            flag = (a[i][j] == b[i][j]);
        }
        cout << (flag ? "YES" : "NO") << endl;
    }
    return 0;
}

Submission

Task問題 C - 最短経路
User nameユーザ名 yuizumi
Created time投稿日時
Language言語 C++11 (Clang++ 3.4)
Status状態 AC
Score得点 100
Source lengthソースコード長 969 Byte
File nameファイル名
Exec time実行時間 42 ms
Memory usageメモリ使用量 932 KB

Test case

Set

Set name Score得点 / Max score Cases
All 100 / 100 00_sample.txt,10_random_00.txt,10_random_01.txt,10_random_02.txt,10_random_03.txt,10_random_04.txt,10_random_05.txt,10_random_06.txt,10_random_07.txt,10_random_08.txt,10_random_09.txt,10_random_10.txt,10_random_11.txt,10_random_12.txt,10_random_13.txt,10_random_14.txt,10_random_15.txt,10_random_16.txt,10_random_17.txt,10_random_18.txt,10_random_19.txt,10_random_20.txt,10_random_21.txt,10_random_22.txt,10_random_23.txt,10_random_24.txt,10_random_25.txt,10_random_26.txt,10_random_27.txt,10_random_28.txt,10_random_29.txt,22_random_30.txt,22_random_31.txt,23_coplete_32.txt,23_coplete_33.txt,24_path_34.txt,24_path_35.txt,25_tree_36.txt,25_tree_37.txt,26_noedge_38.txt,27_dot_39.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample.txt AC 25 ms 800 KB
10_random_00.txt AC 37 ms 796 KB
10_random_01.txt AC 37 ms 924 KB
10_random_02.txt AC 36 ms 808 KB
10_random_03.txt AC 37 ms 928 KB
10_random_04.txt AC 38 ms 804 KB
10_random_05.txt AC 37 ms 804 KB
10_random_06.txt AC 40 ms 932 KB
10_random_07.txt AC 37 ms 932 KB
10_random_08.txt AC 36 ms 796 KB
10_random_09.txt AC 38 ms 928 KB
10_random_10.txt AC 37 ms 928 KB
10_random_11.txt AC 36 ms 812 KB
10_random_12.txt AC 37 ms 928 KB
10_random_13.txt AC 37 ms 928 KB
10_random_14.txt AC 37 ms 932 KB
10_random_15.txt AC 37 ms 924 KB
10_random_16.txt AC 37 ms 928 KB
10_random_17.txt AC 36 ms 928 KB
10_random_18.txt AC 37 ms 928 KB
10_random_19.txt AC 36 ms 792 KB
10_random_20.txt AC 38 ms 800 KB
10_random_21.txt AC 38 ms 804 KB
10_random_22.txt AC 37 ms 804 KB
10_random_23.txt AC 36 ms 844 KB
10_random_24.txt AC 37 ms 928 KB
10_random_25.txt AC 36 ms 916 KB
10_random_26.txt AC 36 ms 804 KB
10_random_27.txt AC 38 ms 800 KB
10_random_28.txt AC 37 ms 800 KB
10_random_29.txt AC 37 ms 932 KB
22_random_30.txt AC 36 ms 812 KB
22_random_31.txt AC 38 ms 800 KB
23_coplete_32.txt AC 42 ms 804 KB
23_coplete_33.txt AC 38 ms 800 KB
24_path_34.txt AC 38 ms 924 KB
24_path_35.txt AC 38 ms 800 KB
25_tree_36.txt AC 37 ms 804 KB
25_tree_37.txt AC 42 ms 804 KB
26_noedge_38.txt AC 38 ms 920 KB
27_dot_39.txt AC 28 ms 800 KB