結果
問題 |
No.1283 Extra Fee
|
ユーザー |
|
提出日時 | 2020-11-08 00:17:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 301 ms / 2,000 ms |
コード長 | 1,107 bytes |
コンパイル時間 | 803 ms |
コンパイル使用メモリ | 79,056 KB |
実行使用メモリ | 12,128 KB |
最終ジャッジ日時 | 2024-11-16 07:07:27 |
合計ジャッジ時間 | 5,620 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<iostream> #include<queue> using namespace std; int N,M; int c[500][500]; long dist[2][500][500]; int d[5]={0,1,0,-1}; main() { cin>>N>>M; for(int i=0;i<M;i++) { int x,y;cin>>x>>y; cin>>c[x-1][y-1]; } for(int i=0;i<N;i++)for(int j=0;j<N;j++) { dist[0][i][j]=dist[1][i][j]=1e18; } priority_queue<pair<long,pair<int,pair<int,int> > > >P; for(int i=0;i<2;i++) { dist[i][0][0]=0; P.push(make_pair(0,make_pair(i,make_pair(0,0)))); } while(!P.empty()) { long cost=-P.top().first; int f=P.top().second.first,x=P.top().second.second.first,y=P.top().second.second.second; P.pop(); if(dist[f][x][y]<cost)continue; for(int r=0;r<4;r++) { int tx=x+d[r],ty=y+d[r+1]; if(tx<0||ty<0||tx>=N||ty>=N)continue; long nxt=cost+c[tx][ty]+1; if(dist[f][tx][ty]>nxt) { dist[f][tx][ty]=nxt; P.push(make_pair(-nxt,make_pair(f,make_pair(tx,ty)))); } if(f==0) { nxt-=c[tx][ty]; if(dist[f+1][tx][ty]>nxt) { dist[f+1][tx][ty]=nxt; P.push(make_pair(-nxt,make_pair(f+1,make_pair(tx,ty)))); } } } } cout<<dist[1][N-1][N-1]<<endl; }