QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560389#7343. Bicycle Racebad_solverWA 56ms9748kbC++233.1kb2024-09-12 15:27:512024-09-12 15:27:53

Judging History

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

  • [2024-09-12 15:27:53]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:9748kb
  • [2024-09-12 15:27:51]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int N = 1e5 + 3, K = 0;
int n, m, s[N * 2];
unordered_map <int, int> g[N];
void upd(int pos, int val, int max_range) {
	for (s[pos += max_range] = val; pos /= 2;)
		s[pos] = max(s[pos * 2], s[pos * 2 + 1]);
}
int get(int b, int e, int max_range) {
	++e;
	int ra = 0, rb = 0;
	for (b += max_range, e += max_range; b < e; b /= 2, e /= 2) {
		if (b % 2) ra = max(ra, s[b++]);
		if (e % 2) rb = max(s[--e], rb);
	}
	return max(ra, rb);
}
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m;
	vector <pii> edges;
	for (int i = 1; i <= m; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		edges.pb({u, v});
		g[u][v] = g[v][u] = w;
	}
	// fix a host
	int ans = 0;
	for (int v = 1; v <= n; ++v) {
		if (sz(g[v]) < 4)
			continue;
		if (sz(g[v]) <= K) {
			vector <pii> nodes;
			for (auto x : g[v]) 
				nodes.pb(x);
			sort(all(nodes));
			vector <pair <pii, int> > vec;
			for (int i = 0; i < sz(nodes); ++i) {
				auto [u1, w1] = nodes[i];
				for (int j = 0; j < i; ++j) {
					auto [u2, w2] = nodes[j];
					if (g[u1].count(u2)) {
						int tot = w1 + w2 + g[u1][u2];
						vec.pb({{i, j}, tot});
					}
				}
			}
			reverse(all(vec));
			for (int i = 0; i <= sz(nodes) * 2; ++i)
				s[i] = 0;
			for (int i = 0; i < sz(vec); ++i) {
				int j = i;
				while (j + 1 < sz(vec) && vec[j + 1].f.f == vec[j].f.f)
					++j;
				for (int k = i; k <= j; ++k) {
					int ret = 0;
					if (vec[k].f.s + 1 < vec[k].f.f)
						ret = get(vec[k].f.s + 1, vec[k].f.f - 1, sz(nodes));
					if (vec[k].f.s > 0)
						ret = max(ret, get(0, vec[k].f.s - 1, sz(nodes)));
					if (vec[k].f.f + 1 < sz(nodes))
						ret = max(ret, get(vec[k].f.f + 1, sz(nodes) - 1, sz(nodes)));
					if (ret > 0)
						ans = max(ans, ret + vec[k].s);
				}
				
				for (int k = i; k <= j; ++k) {
					auto [y, x] = vec[k].f;
					upd(x, vec[k].s, sz(nodes));
				}
				i = j;
			}
			
		}
		else {
			vector <pair <pii, int> > vec;
			for (auto [x, y] : edges) {
				if (!g[v].count(x) || !g[v].count(y))
					continue;
				if (x < y)
					swap(x, y);
				int tot = g[v][x] + g[v][y] + g[x][y];
				vec.pb({{x - 1, y - 1}, tot});
			}
			sort(all(vec));
			reverse(all(vec));
			for (int i = 0; i <= n * 2; ++i)
				s[i] = 0;
			for (int i = 0; i < sz(vec); ++i) {
				int j = i;
				while (j + 1 < sz(vec) && vec[j + 1].f.f == vec[j].f.f)
					++j;
					
				for (int k = i; k <= j; ++k) {
					auto [y, x] = vec[k].f;
					int w = vec[k].s;
					int ret = 0;
					if (x + 1 < y)
						ret = get(x + 1, y - 1, n);
					if (x > 0)
						ret = max(ret, get(0, x - 1, n));
					if (y + 1 < n)
						ret = max(ret, get(y + 1, n - 1, n));
						
					if (ret > 0)
						ans = max(ans, ret + w);
				}
				for (int k = i; k <= j; ++k) {
					auto [y, x] = vec[k].f;
					upd(x, vec[k].s, n);
				}
				i = j;
			}	
		}
	}
	if (!ans) ans = -1;
	cout << ans;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 8956kb

input:

6 9
1 2 3
2 3 1
3 4 2
4 5 1
3 5 7
2 5 2
1 5 3
4 6 2
5 6 1

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 2ms
memory: 9032kb

input:

6 6
1 3 2
1 2 2
2 3 4
3 4 1
3 6 6
1 4 8

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 2ms
memory: 8956kb

input:

5 6
1 4 2
1 3 6
5 2 10
3 2 4
4 2 1
5 4 7

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 8992kb

input:

5 10
2 1 9
3 1 4
3 2 3
4 1 5
4 2 9
4 3 9
5 1 5
5 2 6
5 3 10
5 4 1

output:

43

result:

ok 1 number(s): "43"

Test #5:

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

input:

5 10
2 1 9
3 1 8
3 2 8
4 1 1
4 2 2
4 3 8
5 1 10
5 2 1
5 3 10
5 4 3

output:

46

result:

ok 1 number(s): "46"

Test #6:

score: 0
Accepted
time: 2ms
memory: 9748kb

input:

5 9
1 3 4
4 1 10
1 5 9
5 2 9
3 5 9
2 3 7
5 4 1
2 1 7
2 4 1

output:

45

result:

ok 1 number(s): "45"

Test #7:

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

input:

5 8
2 1 10
5 2 5
1 3 7
3 5 8
3 2 5
2 4 6
4 3 5
4 5 6

output:

41

result:

ok 1 number(s): "41"

Test #8:

score: 0
Accepted
time: 7ms
memory: 9396kb

input:

200 2000
182 97 91166
25 11 25393
179 58 43378
77 41 75588
139 96 94145
135 56 4609
190 159 47293
100 30 33854
21 132 93072
174 135 93547
144 137 81216
199 102 68247
89 155 53788
83 25 64607
166 179 44534
101 3 1474
37 106 57970
187 41 19892
16 76 32024
182 13 32061
72 69 5823
187 185 13918
151 86 3...

output:

552426

result:

ok 1 number(s): "552426"

Test #9:

score: 0
Accepted
time: 29ms
memory: 9384kb

input:

400 4000
102 372 24346
360 153 94255
272 316 33427
215 71 52304
368 202 60854
350 206 16796
32 372 31489
109 14 95840
163 71 79896
330 393 95303
324 110 13216
197 341 69668
54 241 46100
222 246 67388
140 13 539
272 79 22065
389 221 81398
187 122 60482
198 352 4291
196 14 18220
215 93 64141
336 54 54...

output:

545402

result:

ok 1 number(s): "545402"

Test #10:

score: -100
Wrong Answer
time: 56ms
memory: 9552kb

input:

600 6000
270 248 73879
94 543 63116
118 174 23476
152 301 12668
597 557 27564
566 156 28983
322 585 15685
319 598 41474
506 411 50369
334 450 80707
103 83 61569
195 333 71089
219 576 54764
409 18 70169
115 296 72896
92 155 42655
542 537 4827
387 202 1071
209 15 4380
511 165 22459
485 571 94537
570 2...

output:

538784

result:

wrong answer 1st numbers differ - expected: '545966', found: '538784'