Submission #980007

# Submission time Handle Problem Language Result Execution time Memory
980007 2024-05-11T19:11:20 Z HerreraDaniel Closing Time (IOI23_closing) C++17
0 / 100
95 ms 25928 KB
#include "closing.h"

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

using ll  = long long;
using pll = pair<ll, ll>;

ll countCities(vector<vector<pll>>& g, vector<ll>& c, ll X) {
	queue<pll> q;
	q.push({X, 0});

	ll           cnt = 0;
	vector<bool> v(g.size() + 1);
	while (q.size()) {
		ll curr = q.front().first, pC = q.front().second;
		q.pop();

		if (pC > c[curr] || v[curr]) continue;
		v[curr] = true;
		cnt++;

		for (pll& nei : g[curr])
			if (!v[nei.first]) q.push({nei.first, nei.second + pC});
	}

	return cnt;
}

int max_score(int N, int X, int Y, long long K, std::vector<int> U,
              std::vector<int> V, std::vector<int> W) {
	ll sum = 0;

	vector<vector<pll>> g(N + 1);
	for (int i = 0; i < N; i++) {
		ll a = U[i], b = V[i], c = W[i];
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}

	priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
	               greater<pair<ll, pll>>>
	  q;
	q.push({0, {X, X}});
	q.push({0, {Y, Y}});

	vector<ll>               c(N, 0);
	vector<pair<bool, bool>> v(N);

	while (q.size()) {
		ll pC = q.top().first, curr = q.top().second.second,
		   source = q.top().second.first;
		q.pop();

		if (source == X && v[curr].first) continue;
		else if (source == X)
			v[curr].first = true;

		if (source == Y && v[curr].second) continue;
		else if (source == Y)
			v[curr].second = true;

		ll cost = pC - c[curr];
		if (sum + cost > K) continue;

		sum += cost;
		c[curr] = pC;

		for (pll& nei : g[curr])
			if ((source == X && v[nei.first].first)
			    || (source == Y && v[nei.first].second))
				continue;
			else
				q.push({nei.second + pC, {source, nei.first}});
	}

	return countCities(g, c, X) + countCities(g, c, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 22096 KB Output is correct
2 Correct 95 ms 25928 KB Output is correct
3 Incorrect 52 ms 5448 KB 5th lines differ - on the 1st token, expected: '52', found: '56'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -