結果
問題 | No.614 壊れたキャンパス |
ユーザー |
|
提出日時 | 2020-02-27 21:35:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 1,234 bytes |
コンパイル時間 | 537 ms |
コンパイル使用メモリ | 58,696 KB |
実行使用メモリ | 24,752 KB |
最終ジャッジ日時 | 2024-10-13 16:02:15 |
合計ジャッジ時間 | 2,866 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 9 | main() | ^~~~
ソースコード
#include<cstdio> #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() { scanf("%d%d%d%d%d",&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; scanf("%d%d%d",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]; printf("%ld\n",ans<1e18?ans:-1L); }