Submission #723932

# Submission time Handle Problem Language Result Execution time Memory
723932 2023-04-14T13:25:09 Z LittleCube Sky Walking (IOI19_walk) C++14
0 / 100
1848 ms 890072 KB
#include "walk.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, M, K, S, T, dis[2000000];
vector<pll> E[2000000], ver[100000], hor[100000], table[100000][20];

ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g)
{
	N = x.size(), M = l.size();
	for (int i = 0; i < N; i++)
		table[i][0].emplace_back(pll(x[i], i));
	for (int p = 0; p + 1 < 18; p++)
		for (int i = 0; i + (1 << p) < N; i++)
		{
			for (auto j : table[i][p])
				table[i][p + 1].emplace_back(j);
			for (auto j : table[i + (1 << p)][p])
				table[i][p + 1].emplace_back(j);
			sort(table[i][p + 1].begin(), table[i][p + 1].end());
			if (table[i][p + 1].size() > 10)
				table[i][p + 1].resize(10);
		}
	for (int i = 0; i < N; i++)
	{
		++K;
		ver[i].emplace_back(pll(0, K));
		if (i == s)
			S = K;
		if (i == g)
			T = K;
	}
	for (int i = 0; i < M; i++)
	{
		int lg = __lg(r[i] - l[i]);
		vector<pll> mango;
		for (auto j : table[l[i]][lg])
			mango.emplace_back(j);
		for (auto j : table[r[i] - (1 << lg) + 1][lg])
			mango.emplace_back(j);

		for (auto [_, j] : mango)
		{
			if (y[i] <= h[j])
			{
				++K;
				ver[j].emplace_back(pll(y[i], K));
				hor[i].emplace_back(pll(x[j], K));
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		sort(ver[i].begin(), ver[i].end());
		for (int j = 0; j + 1 < ver[i].size(); j++)
			E[ver[i][j].S].emplace_back(ver[i][j + 1].S, ver[i][j + 1].F - ver[i][j].F),
				E[ver[i][j + 1].S].emplace_back(ver[i][j].S, ver[i][j + 1].F - ver[i][j].F);
	}
	for (int i = 0; i < M; i++)
	{
		sort(hor[i].begin(), hor[i].end());
		for (int j = 0; j + 1 < hor[i].size(); j++)
			E[hor[i][j].S].emplace_back(hor[i][j + 1].S, hor[i][j + 1].F - hor[i][j].F),
				E[hor[i][j + 1].S].emplace_back(hor[i][j].S, hor[i][j + 1].F - hor[i][j].F);
	}
	for (int i = 0; i <= K; i++)
		dis[i] = 1e18;
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	dis[S] = 0;
	pq.push(pll(0, S));
	while (!pq.empty())
	{
		auto [d, u] = pq.top();
		pq.pop();
		if (d > dis[u])
			continue;
		for (auto [v, w] : E[u])
			if (dis[u] + w < dis[v])
			{
				dis[v] = dis[u] + w;
				pq.push(pll(dis[v], v));
			}
	}
	return (dis[T] >= 1e18 ? -1 : dis[T]);
}

Compilation message

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:47:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |   for (auto [_, j] : mango)
      |             ^
walk.cpp:60:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for (int j = 0; j + 1 < ver[i].size(); j++)
      |                   ~~~~~~^~~~~~~~~~~~~~~
walk.cpp:67:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for (int j = 0; j + 1 < hor[i].size(); j++)
      |                   ~~~~~~^~~~~~~~~~~~~~~
walk.cpp:78:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |   auto [d, u] = pq.top();
      |        ^
walk.cpp:82:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |   for (auto [v, w] : E[u])
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 54 ms 98892 KB Output is correct
2 Correct 50 ms 98892 KB Output is correct
3 Correct 58 ms 98900 KB Output is correct
4 Correct 49 ms 98920 KB Output is correct
5 Correct 58 ms 99016 KB Output is correct
6 Correct 53 ms 98964 KB Output is correct
7 Incorrect 51 ms 98980 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 98840 KB Output is correct
2 Correct 48 ms 98920 KB Output is correct
3 Correct 941 ms 283336 KB Output is correct
4 Correct 1848 ms 890072 KB Output is correct
5 Incorrect 1428 ms 869724 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 231 ms 165064 KB Output is correct
2 Incorrect 1621 ms 370780 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 231 ms 165064 KB Output is correct
2 Incorrect 1621 ms 370780 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 98892 KB Output is correct
2 Correct 50 ms 98892 KB Output is correct
3 Correct 58 ms 98900 KB Output is correct
4 Correct 49 ms 98920 KB Output is correct
5 Correct 58 ms 99016 KB Output is correct
6 Correct 53 ms 98964 KB Output is correct
7 Incorrect 51 ms 98980 KB Output isn't correct
8 Halted 0 ms 0 KB -