結果

問題 No.614 壊れたキャンパス
ユーザー kotatsugamekotatsugame
提出日時 2020-02-27 21:33:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,211 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 79,032 KB
実行使用メモリ 23,808 KB
最終ジャッジ日時 2024-04-21 17:05:11
合計ジャッジ時間 5,645 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,728 KB
testcase_01 AC 7 ms
9,600 KB
testcase_02 AC 6 ms
9,600 KB
testcase_03 AC 7 ms
9,728 KB
testcase_04 AC 7 ms
9,600 KB
testcase_05 AC 6 ms
9,728 KB
testcase_06 AC 6 ms
9,600 KB
testcase_07 AC 6 ms
9,600 KB
testcase_08 AC 192 ms
23,808 KB
testcase_09 AC 275 ms
22,864 KB
testcase_10 AC 314 ms
23,040 KB
testcase_11 AC 198 ms
22,400 KB
testcase_12 AC 267 ms
22,528 KB
testcase_13 AC 215 ms
22,528 KB
testcase_14 AC 227 ms
23,808 KB
testcase_15 AC 222 ms
22,784 KB
testcase_16 AC 213 ms
23,552 KB
testcase_17 AC 270 ms
23,040 KB
testcase_18 AC 204 ms
21,556 KB
testcase_19 AC 190 ms
21,684 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M,K,S,T;
int a[2<<17],b[2<<17],c[2<<17];
long dist[2<<17];
vector<pair<int,long> >X[2<<17];
main()
{
	cin>>N>>M>>K>>S>>T;
	X[N-1].push_back(make_pair(T,-M-1));
	dist[M+1]=1e18;
	for(int i=0;i++<M;)
	{
		dist[i]=1e18;
		cin>>a[i]>>b[i]>>c[i];
		a[i]--;
		X[a[i]].push_back(make_pair(b[i],-i));
	}
	X[0].push_back(make_pair(S,0));
	for(int i=0;i<N;i++)
	{
		sort(X[i].begin(),X[i].end());
		long now=1e18,pre=0;
		int n=X[i].size();
		for(int j=0;j<n;j++)
		{
			now+=X[i][j].first-pre;
			pre=X[i][j].first;
			if(X[i][j].second>=0)
			{
				now=min(now,X[i][j].second);
			}
			else
			{
				int id=-X[i][j].second;
				dist[id]=min(dist[id],now);
			}
		}
		now=1e18,pre=1e9;
		for(int j=n;j--;)
		{
			now+=pre-X[i][j].first;
			pre=X[i][j].first;
			if(X[i][j].second>=0)
			{
				now=min(now,X[i][j].second);
			}
			else
			{
				int id=-X[i][j].second;
				dist[id]=min(dist[id],now);
			}
		}
		if(i+1<N)
		{
			for(int j=0;j<n;j++)
			{
				if(X[i][j].second<0)
				{
					int id=-X[i][j].second;
					X[i+1].push_back(make_pair(c[id],dist[id]));
				}
			}
		}
	}
	long ans=dist[M+1];
	cout<<(ans<1e18?ans:-1)<<endl;
}
0