結果
問題 | No.614 壊れたキャンパス |
ユーザー | rickytheta |
提出日時 | 2017-12-14 01:08:53 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 979 ms / 2,000 ms |
コード長 | 2,317 bytes |
コンパイル時間 | 2,199 ms |
コンパイル使用メモリ | 181,260 KB |
実行使用メモリ | 70,784 KB |
最終ジャッジ日時 | 2024-05-08 08:16:54 |
合計ジャッジ時間 | 12,125 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
19,584 KB |
testcase_01 | AC | 8 ms
19,328 KB |
testcase_02 | AC | 8 ms
19,584 KB |
testcase_03 | AC | 8 ms
19,456 KB |
testcase_04 | AC | 8 ms
19,456 KB |
testcase_05 | AC | 8 ms
19,584 KB |
testcase_06 | AC | 9 ms
19,584 KB |
testcase_07 | AC | 8 ms
19,584 KB |
testcase_08 | AC | 900 ms
69,504 KB |
testcase_09 | AC | 919 ms
67,756 KB |
testcase_10 | AC | 692 ms
69,120 KB |
testcase_11 | AC | 933 ms
70,144 KB |
testcase_12 | AC | 979 ms
70,144 KB |
testcase_13 | AC | 938 ms
70,272 KB |
testcase_14 | AC | 914 ms
70,784 KB |
testcase_15 | AC | 682 ms
69,248 KB |
testcase_16 | AC | 819 ms
69,760 KB |
testcase_17 | AC | 429 ms
68,736 KB |
testcase_18 | AC | 419 ms
61,344 KB |
testcase_19 | AC | 398 ms
59,928 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:44:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | scanf("%d%d%d%d%d",&n,&m,&k,&s,&t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:45:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | REP(i,m)scanf("%d%d%d",a+i,b+i,c+i); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() #define CHMIN(a,b) a=min((a),(b)) #define CHMAX(a,b) a=max((a),(b)) // mod const ll MOD = 1000000007ll; #define FIX(a) ((a)%MOD+MOD)%MOD // floating typedef double Real; const Real EPS = 1e-11; #define EQ0(x) (abs(x)<EPS) #define EQ(a,b) (abs(a-b)<EPS) typedef complex<Real> P; int n,m,k,s,t; int a[252521], b[252521], c[252521]; vi po[252521]; map<pii,int> vrtx; vector<pii> g[425252]; ll dist[425252]; int main(){ scanf("%d%d%d%d%d",&n,&m,&k,&s,&t); REP(i,m)scanf("%d%d%d",a+i,b+i,c+i); po[0].push_back(s); po[n-1].push_back(t); REP(i,m){ a[i]--; po[a[i]].push_back(b[i]); po[a[i]+1].push_back(c[i]); } int it = 0; REP(i,n){ sort(ALL(po[i])); po[i].erase(unique(ALL(po[i])), po[i].end()); REP(j,po[i].size()){ vrtx[pii(i,po[i][j])] = it++; } REP(j,po[i].size()-1){ int from = vrtx[pii(i,po[i][j])]; int to = vrtx[pii(i,po[i][j+1])]; int sa = po[i][j+1] - po[i][j]; g[from].push_back(pii(to,sa)); g[to].push_back(pii(from,sa)); } } REP(i,m){ int from = vrtx[pii(a[i], b[i])]; int to = vrtx[pii(a[i]+1, c[i])]; g[from].push_back(pii(to,0)); } const ll INF = 1e18; REP(i,it)dist[i] = INF; priority_queue<pll> Q; int start = vrtx[pii(0,s)]; dist[start] = 0ll; Q.push(pll(-dist[start], start)); while(!Q.empty()){ ll d = Q.top().first; int pos = Q.top().second; Q.pop(); if(dist[pos] != -d)continue; for(pii P : g[pos]){ int to = P.first; int cost = P.second; if(dist[pos] + cost < dist[to]){ dist[to] = dist[pos] + cost; Q.push(pll(-dist[to], to)); } } } int goal = vrtx[pii(n-1,t)]; if(dist[goal] == INF){ dist[goal] = -1; } cout<<dist[goal]<<endl; return 0; }