Submission #843227

# Submission time Handle Problem Language Result Execution time Memory
843227 2023-09-03T19:43:25 Z yifei04 Closing Time (IOI23_closing) C++17
0 / 100
91 ms 23388 KB
#include "closing.h"

#include <vector>
#include <queue>
#include <array>
#include <algorithm>
#include <iostream>
#include <set>

#define ll long long
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()

using namespace std;

template <typename T>
void dbg_vec(string str, vector <T> &x) {
    cerr << "DBG " << str << '\n';
    for (int i = 0; i < sz(x); ++i) {
        cerr << "I " << i << " -> " << x[i] << '\n';
    }
    cerr << '\n';
}


int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
	vector <vector <array <int, 2> > > g (N);

	for (int i = 0; i < sz(U); ++i) {
		g[U[i]].push_back({V[i], W[i]});
		g[V[i]].push_back({U[i], W[i]});
	}    

	auto bfs = [&] (int source) -> vector <ll> {
		vector <ll> dist (N, -1);
		queue <int> coda;
		dist[source] = 0;
		coda.push(source);

		while (!coda.empty()) {
			int node = coda.front();
			coda.pop();

			for (auto [to, w] : g[node]) {
				if (dist[to] == -1) {
					dist[to] = dist[node] + w;
					coda.push(to);
				}
			}
		}

		return dist;
	};

	vector <ll> dist_x = bfs(X);
	vector <ll> dist_y = bfs(Y);

	
	vector <pair <ll, int> > dist_node;

	for (int i = 0; i < N; ++i) {
		if (dist_x[i] <= K) { 
			dist_node.push_back({dist_x[i], i});
		}
		if (dist_y[i] <= K) {
			dist_node.push_back({dist_y[i], i});
		}
	} 

	sort(all(dist_node));

	vector <int> idx_node (N, -1);
	vector <bool> is_sec (sz(dist_node));

	for (int i = 0; i< sz(dist_node); ++i) {
		int nd = dist_node[i].second;
		if (idx_node[nd] == -1) {
			idx_node[nd] = i;
		} else {
			is_sec[i] = true;
			int prv = idx_node[nd];
			dist_node[i].first -= dist_node[prv].first;
		}
	}

	vector <ll> pref (sz(dist_node) + 1);

	for (int i = 0; i < sz(dist_node); ++i) {
		pref[i + 1] = pref[i] + dist_node[i].first;
	}

	auto bs = [&] (int l, int r, ll v) {
		int mid, ans = -1;
		while (l <= r) {
			mid = (l + r) >> 1;
			if (v + pref[mid] <= K) {
				ans = mid;
				l = mid + 1;
			} else {
				r = mid - 1;
			}
		}

		return ans;
	};

	int ans = -1;

	for (int i = 0; i < sz(dist_node); ++i) {
		if (is_sec[i]) { 
			int nd = dist_node[i].second;
			int idx = bs(idx_node[nd], i - 1, dist_node[i].first);
			if (idx != -1) {
				ans = max(ans, idx);
			}
		} else {
			int idx = bs(0, i - 1, dist_node[i].first);
			ans = max(ans, idx);
		}
	}
	return ans;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 23388 KB 1st lines differ - on the 1st token, expected: '451', found: '450'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -