Submission #1868046


Source Code Expand

#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

const ll INF = 1e9;
ll n, ans;
ll a[305][305];
bool bo[305][305];

int main()
{
    scanf("%lld", &n);
//    for(ll i = 1; i <= n; i++) for(ll j = 1; j <= n; j++) a[i][j] = INF;
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 1; j <= n; j++)
        {
            scanf("%lld", &a[i][j]);
        }
    }
    for(ll k = 1; k <= n; k++)
    {
        for(ll i = 1; i <= n; i++)
        {
            for(ll j = 1; j <= n; j++)
            {
                if(i == k || j == k || i == j) continue;
                if(a[i][j] > a[i][k] + a[k][j]) {printf("-1"); return 0;}
                if(a[i][j] == a[i][k] + a[k][j])
                {
                    bo[i][j] = true;
                }
            }
        }
    }
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 1; j <= n; j++)
        {
            ans += (1 - bo[i][j]) * a[i][j];
        }
    }
    printf("%lld", ans / 2);
    return 0;
}

Submission Info

Submission Time
Task D - Restoring Road Network
User mathking1021
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1051 Byte
Status AC
Exec Time 65 ms
Memory 1280 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &n);
                      ^
./Main.cpp:21:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &a[i][j]);
                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 17
Set Name Test Cases
Sample subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt
Case Name Status Exec Time Memory
01.txt AC 65 ms 1280 KB
02.txt AC 65 ms 1024 KB
03.txt AC 65 ms 1024 KB
04.txt AC 60 ms 1024 KB
05.txt AC 60 ms 1024 KB
06.txt AC 58 ms 1024 KB
07.txt AC 10 ms 1024 KB
08.txt AC 60 ms 1024 KB
09.txt AC 60 ms 1024 KB
10.txt AC 10 ms 1024 KB
11.txt AC 10 ms 1024 KB
12.txt AC 11 ms 1024 KB
13.txt AC 1 ms 256 KB
subtask0_0.txt AC 1 ms 256 KB
subtask0_1.txt AC 1 ms 256 KB
subtask0_2.txt AC 1 ms 256 KB
subtask0_3.txt AC 1 ms 256 KB