QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781118#5579. Bog of Eternal Stenchcyj888WA 151ms3956kbC++141.3kb2024-11-25 14:51:112024-11-25 14:51:12

Judging History

你现在查看的是最新测评结果

  • [2024-11-25 14:51:12]
  • 评测
  • 测评结果:WA
  • 用时:151ms
  • 内存:3956kb
  • [2024-11-25 14:51:11]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin (), x.end ()
#define ott(i,l,r) for (int i = l; i <= r; i ++)
#define tto(i,l,r) for (int i = r; i >= l; i --)
using namespace std;
using ll = long long;
int read () {
	int x = 0; bool f = 0; char c = getchar ();
	while (!isdigit (c)) f |= (c == '-'), c = getchar ();
	while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
	if (f) x = -x; return x;
}
const int N = 2200, mod = 1e9 + 7, inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int T, n, m;
vector <array <int, 3> > a;
ll dis[N];
bool check (ll val) {
	memset (dis, -0x3f, sizeof dis); dis[n] = val;
	ott (i, 1, n)
		for (auto [u, v, w] : a) 
			if (dis[u] >= 0 && dis[u] + w >= 0 && dis[v] < dis[u] + w)
				dis[v] = dis[u] + w;
	for (auto [u, v, w] : a)
		if (dis[u] >= 0 && dis[u] + w >= 0 && dis[v] < dis[u] + w)
			dis[v] = INF;
	ott (i, 1, n)
		for (auto [u, v, w] : a) 
			if (dis[u] == INF)
				dis[v] = INF;
	return dis[1] >= 0;
}
int main () {
	n = read (), m = read ();
	ott (i, 1, m) {
		int x = read (), y = read (), z = read ();
		a.pb ({y, x, -z});
	}
	ll l = 0, r = inf, res = -1;
	while (l <= r) {
		ll mid = l + r >> 1;
		if (check (mid)) r = mid - 1, res = mid;
		else l = mid + 1;
	}
	printf ("%lld\n", res);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 151ms
memory: 3888kb

input:

1999 1999
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
6 7 1000000000
7 8 1000000000
8 9 1000000000
9 10 1000000000
10 11 1000000000
11 12 1000000000
12 13 1000000000
13 14 1000000000
14 15 1000000000
15 16 1000000000
16 17 1000000000
17 18 1000000000
18 19 1000000000
1...

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

4 4
1 2 5
1 3 -2
2 4 1
3 4 10

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

5 5
1 2 1000
2 3 -3
3 4 1
4 2 0
2 5 2

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

3 3
1 3 -10
3 2 2
2 3 -1

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

2 1
1 2 0

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

6 6
1 2 1000000000
2 6 -1
3 2 0
4 3 -1
3 5 -1
5 4 -1

output:

999999999

result:

ok single line: '999999999'

Test #7:

score: 0
Accepted
time: 5ms
memory: 3880kb

input:

46 1981
29 18 40
29 4 44
17 44 65
42 10 99
26 5 95
12 31 -3
18 4 100
27 34 69
5 35 22
29 9 -5
29 27 16
25 19 4
10 12 75
39 23 83
41 21 51
46 45 35
34 10 4
29 8 30
16 30 82
18 19 62
37 38 8
37 18 9
11 27 68
40 31 71
28 44 90
6 19 70
14 26 64
40 17 87
24 5 91
33 35 -1
10 2 23
22 35 17
14 18 31
45 28 7...

output:

2

result:

ok single line: '2'

Test #8:

score: 0
Accepted
time: 5ms
memory: 3884kb

input:

46 1981
29 18 47
29 4 71
17 44 26
42 10 50
26 5 13
12 31 41
18 4 57
27 34 83
5 35 76
29 9 0
29 27 21
25 19 2
10 12 99
39 23 47
41 21 91
46 45 67
34 10 75
29 8 86
16 30 58
18 19 4
37 38 70
37 18 -3
11 27 -2
40 31 84
28 44 88
6 19 84
14 26 12
40 17 52
24 5 95
33 35 63
10 2 60
22 35 67
14 18 17
45 28 1...

output:

7

result:

ok single line: '7'

Test #9:

score: 0
Accepted
time: 5ms
memory: 3900kb

input:

46 1981
29 18 10
29 4 47
17 44 43
42 10 6
26 5 27
12 31 13
18 4 25
27 34 14
5 35 72
29 9 55
29 27 87
25 19 72
10 12 21
39 23 8
41 21 20
46 45 40
34 10 63
29 8 64
16 30 72
18 19 63
37 38 35
37 18 1
11 27 95
40 31 47
28 44 41
6 19 12
14 26 11
40 17 21
24 5 60
33 35 91
10 2 13
22 35 34
14 18 14
45 28 6...

output:

1000000001

result:

ok single line: '1000000001'

Test #10:

score: -100
Wrong Answer
time: 143ms
memory: 3944kb

input:

2000 1999
1205 1206 1000000000
1191 1192 1000000000
702 703 1000000000
1769 1770 1000000000
1060 1061 1000000000
469 470 1000000000
707 708 1000000000
1132 1133 1000000000
165 166 1000000000
1196 1197 1000000000
1214 1215 1000000000
1030 1031 1000000000
362 363 1000000000
1650 1651 1000000000
1736 1...

output:

-1

result:

wrong answer 1st lines differ - expected: '1999000000000', found: '-1'