Submission #6817542


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

int n, m, p;
long long x[2505], ans = LLONG_MIN, best;
vector<pair<int, long long>> v[2505];

int main() {
	scanf("%d%d%d", &n, &m, &p);
	for (int i = 2; i <= n; i++)
		x[i] = LLONG_MIN;
	while (m--) {
		int ta, tb, tc;
		scanf("%d%d%d", &ta, &tb, &tc);
		v[ta].emplace_back(tb, tc);
	}
	for (int i = 0; i <= n * 4; i++) {
		for (int j = 1; j <= n; j++)
			if (x[j] != LLONG_MIN)
				for (auto& k : v[j])
					x[k.first] = max(x[k.first], x[j] + k.second - p);
		ans = max(ans, x[n]);
		if (i == n * 3)
			best = ans;
		if (i != n * 4)
			continue;
		if (best == ans)
			printf("%lld\n", max(0LL, ans));
		else
			puts("-1");
	}
}

Submission Info

Submission Time
Task E - Coins Respawn
User nhho
Language C++14 (GCC 5.4.1)
Score 500
Code Size 712 Byte
Status AC
Exec Time 181 ms
Memory 512 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:10:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &p);
                             ^
./Main.cpp:15:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &ta, &tb, &tc);
                                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 56
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 80 ms 384 KB
b10 AC 75 ms 384 KB
b11 AC 74 ms 384 KB
b12 AC 92 ms 384 KB
b13 AC 92 ms 384 KB
b14 AC 74 ms 384 KB
b15 AC 2 ms 512 KB
b16 AC 2 ms 512 KB
b17 AC 2 ms 512 KB
b18 AC 75 ms 384 KB
b19 AC 74 ms 384 KB
b20 AC 80 ms 384 KB
b21 AC 76 ms 384 KB
b22 AC 18 ms 384 KB
b23 AC 79 ms 384 KB
b24 AC 18 ms 384 KB
b25 AC 18 ms 384 KB
b26 AC 173 ms 512 KB
b27 AC 178 ms 512 KB
b28 AC 174 ms 512 KB
b29 AC 176 ms 512 KB
b30 AC 172 ms 512 KB
b31 AC 181 ms 512 KB
b32 AC 169 ms 512 KB
b33 AC 165 ms 512 KB
b34 AC 166 ms 512 KB
b35 AC 171 ms 512 KB
b36 AC 167 ms 512 KB
b37 AC 169 ms 512 KB
b38 AC 168 ms 512 KB
b39 AC 168 ms 384 KB
b40 AC 170 ms 512 KB
b41 AC 169 ms 512 KB
b42 AC 166 ms 384 KB
b43 AC 142 ms 512 KB
b44 AC 150 ms 512 KB
b45 AC 150 ms 512 KB
b46 AC 145 ms 512 KB
b47 AC 19 ms 512 KB
b48 AC 68 ms 384 KB
b49 AC 76 ms 384 KB
b50 AC 75 ms 384 KB
b51 AC 74 ms 384 KB
b52 AC 75 ms 384 KB
b53 AC 75 ms 384 KB
b54 AC 150 ms 512 KB
b55 AC 128 ms 512 KB
b56 AC 123 ms 512 KB