提出 #2764689
ソースコード 拡げる
import sys
import copy
N = int(input())
table = []
for i in range(N):
A = [int(j) for j in input().split()]
table.append(A)
tas = copy.deepcopy(table)
for k in range(N):
for i in range(N):
for j in range(N):
tas[j][i] = min(tas[j][i], tas[j][k] + tas[k][i])
for y in range(N):
for x in range(y+1, N):
if table[y][x] != tas[y][x]:
print(-1)
sys.exit()
ans = 0
for i in range(N):
for j in range(i + 1, N):
flag = True
for k in range(N):
if i == k or j == k:
continue
if table[j][i] >= table[j][k] + table[k][i]:
flag = False
if flag:
ans += table[j][i]
print(ans)
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Restoring Road Network |
| ユーザ | okumura |
| 言語 | PyPy3 (2.4.0) |
| 得点 | 500 |
| コード長 | 765 Byte |
| 結果 | AC |
| 実行時間 | 965 ms |
| メモリ | 58588 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01.txt | AC | 924 ms | 58588 KiB |
| 02.txt | AC | 899 ms | 56924 KiB |
| 03.txt | AC | 965 ms | 56668 KiB |
| 04.txt | AC | 950 ms | 57308 KiB |
| 05.txt | AC | 929 ms | 56924 KiB |
| 06.txt | AC | 875 ms | 56668 KiB |
| 07.txt | AC | 748 ms | 54748 KiB |
| 08.txt | AC | 862 ms | 55772 KiB |
| 09.txt | AC | 879 ms | 55644 KiB |
| 10.txt | AC | 705 ms | 54876 KiB |
| 11.txt | AC | 760 ms | 54620 KiB |
| 12.txt | AC | 769 ms | 55004 KiB |
| 13.txt | AC | 164 ms | 38256 KiB |
| subtask0_0.txt | AC | 164 ms | 38256 KiB |
| subtask0_1.txt | AC | 164 ms | 38256 KiB |
| subtask0_2.txt | AC | 165 ms | 38256 KiB |
| subtask0_3.txt | AC | 164 ms | 38256 KiB |