답안 #723938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723938 2023-04-14T13:32:46 Z LittleCube Sky Walking (IOI19_walk) C++14
0 / 100
1784 ms 606832 KB
#pragma GCC optimize("Ofast")
#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[5000000];
vector<pii> E[5000000], ver[100005], hor[100005], table[100005][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(), greater<pll>());
			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] + 1);
		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));
			}
	}
	assert(K < 5000000);
	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:48:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |   for (auto [_, j] : mango)
      |             ^
walk.cpp:61:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for (int j = 0; j + 1 < ver[i].size(); j++)
      |                   ~~~~~~^~~~~~~~~~~~~~~
walk.cpp:68:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int j = 0; j + 1 < hor[i].size(); j++)
      |                   ~~~~~~^~~~~~~~~~~~~~~
walk.cpp:79:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   79 |   auto [d, u] = pq.top();
      |        ^
walk.cpp:83:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   83 |   for (auto [v, w] : E[u])
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 169252 KB Output is correct
2 Correct 93 ms 169304 KB Output is correct
3 Correct 117 ms 169488 KB Output is correct
4 Correct 120 ms 169396 KB Output is correct
5 Correct 99 ms 169412 KB Output is correct
6 Incorrect 95 ms 169432 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 169288 KB Output is correct
2 Correct 102 ms 169260 KB Output is correct
3 Correct 999 ms 290248 KB Output is correct
4 Correct 1784 ms 606832 KB Output is correct
5 Incorrect 1365 ms 593172 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 213660 KB Output is correct
2 Incorrect 1572 ms 336100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 213660 KB Output is correct
2 Incorrect 1572 ms 336100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 169252 KB Output is correct
2 Correct 93 ms 169304 KB Output is correct
3 Correct 117 ms 169488 KB Output is correct
4 Correct 120 ms 169396 KB Output is correct
5 Correct 99 ms 169412 KB Output is correct
6 Incorrect 95 ms 169432 KB Output isn't correct
7 Halted 0 ms 0 KB -