Submission #140341

# Submission time Handle Problem Language Result Execution time Memory
140341 2019-08-02T14:59:49 Z nhc7502 None (JOI14_ho_t4) C++14
25 / 100
867 ms 9192 KB
///EVERYONE BELIEVE IN GODTAEGYU
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000;
int n, m, i, j, k;
int x, h[100141];
vector<pair<int,int>>graph[100141];
unordered_map<long long, int>dist;
priority_queue<pair<int,pair<int,int>>>pq;

inline pair<int,int> lltop(long long x)
{
	return {x/MOD, x%MOD};
}

inline long long ptoll(pair<int,int> x)
{
	return x.first * MOD + x.second;
}

void f(int tree, int godo, int thist)
{
	if(dist.find(ptoll({tree, godo})) == dist.end())
	{
		dist[ptoll({tree, godo})] = thist;
		pq.push({thist, {tree, godo}});
	}
	else if(dist[ptoll({tree, godo})] > thist)
	{
		dist[ptoll({tree, godo})] = thist;
		pq.push({thist, {tree, godo}});
	}
}

int main(){
	iostream::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	for(cin>>n>>m>>x; i<n;)
	{
		cin>>h[++i];
	}
	for(;m--;)
	{
		cin>>i>>j>>k;
		if(h[i] >= k)
			graph[i].push_back({j, k});
		if(h[j] >= k)
			graph[j].push_back({i, k});
	}
	dist[ptoll({1, x})] = 0;
	pq.push({0,{1,x}});
	while(!pq.empty())
	{
		x = pq.top().first;
		tie(m, i) = pq.top().second;
		pq.pop();
		if(dist[ptoll({m, i})] != x)
			continue;
		for(auto next : graph[m])
		{	//m = 현재 나무, i = 현재 높이, j = 다음 나무, k = 다음 나무 거리
			tie(j, k) = next;
			if(i < k) f(j, 0, x + k - i + k);
			else if(i - k > h[j]) f(j, h[j], x + i - h[j]);
			else f(j, i - k, x + k);
		}
		if(m == n)
			f(n, h[n], x + h[n] - i);
	}
	if(dist.find(ptoll({n, h[n]})) == dist.end())
		cout<<-1;
	else cout<<dist[ptoll({n,h[n]})];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 51 ms 2876 KB Output is correct
3 Correct 49 ms 2904 KB Output is correct
4 Correct 8 ms 2808 KB Output is correct
5 Correct 20 ms 2808 KB Output is correct
6 Correct 4 ms 2652 KB Output is correct
7 Correct 5 ms 2936 KB Output is correct
8 Correct 50 ms 2808 KB Output is correct
9 Correct 28 ms 2808 KB Output is correct
10 Correct 37 ms 2936 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 56 ms 2808 KB Output is correct
13 Correct 51 ms 2916 KB Output is correct
14 Correct 13 ms 2808 KB Output is correct
15 Correct 48 ms 2864 KB Output is correct
16 Correct 5 ms 2808 KB Output is correct
17 Correct 5 ms 2684 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 5 ms 2680 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 867 ms 9192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 51 ms 2876 KB Output is correct
3 Correct 49 ms 2904 KB Output is correct
4 Correct 8 ms 2808 KB Output is correct
5 Correct 20 ms 2808 KB Output is correct
6 Correct 4 ms 2652 KB Output is correct
7 Correct 5 ms 2936 KB Output is correct
8 Correct 50 ms 2808 KB Output is correct
9 Correct 28 ms 2808 KB Output is correct
10 Correct 37 ms 2936 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 56 ms 2808 KB Output is correct
13 Correct 51 ms 2916 KB Output is correct
14 Correct 13 ms 2808 KB Output is correct
15 Correct 48 ms 2864 KB Output is correct
16 Correct 5 ms 2808 KB Output is correct
17 Correct 5 ms 2684 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 5 ms 2680 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Incorrect 867 ms 9192 KB Output isn't correct
22 Halted 0 ms 0 KB -