Submission #4635104


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N; cin >> N;
	VVL a(N, VL(N));
	FOR(i, 0, N) {
		FOR(j, 0, N) {
			cin >> a[i][j];
		}
	}

	bool ok = 1;
	VVL use(N, VL(N, 1));
	FOR(k, 0, N) {
		FOR(i, 0, N) {
			FOR(j, 0, N) {
				ok &= (a[i][j] <= a[i][k] + a[k][j]);
				if (i != j && j != k && i != k && (a[i][j] == a[i][k] + a[k][j])) {
					use[i][j] = 0;
				}
			}
		}
	}


	LL ans = 0;
	FOR(i, 0, N) {
		FOR(j, i, N) {
			if (use[i][j])ans += a[i][j];
		}
	}
	cout << (ok ? ans : -1) << endl;

	return 0;
}

Submission Info

Submission Time
Task D - Restoring Road Network
User Yang33
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1742 Byte
Status AC
Exec Time 71 ms
Memory 1664 KiB

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 68 ms 1664 KiB
02.txt AC 70 ms 1664 KiB
03.txt AC 71 ms 1664 KiB
04.txt AC 67 ms 1664 KiB
05.txt AC 66 ms 1664 KiB
06.txt AC 62 ms 1664 KiB
07.txt AC 67 ms 1664 KiB
08.txt AC 71 ms 1664 KiB
09.txt AC 65 ms 1664 KiB
10.txt AC 67 ms 1664 KiB
11.txt AC 66 ms 1664 KiB
12.txt AC 61 ms 1664 KiB
13.txt AC 1 ms 256 KiB
subtask0_0.txt AC 1 ms 256 KiB
subtask0_1.txt AC 1 ms 256 KiB
subtask0_2.txt AC 1 ms 256 KiB
subtask0_3.txt AC 1 ms 256 KiB