Submission #00014
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include<bits/stdc++.h> using namespace std; typedef long long int iid; typedef pair< int , int > P; typedef pair<iid, int > Pd; typedef pair<P, int > Pii; typedef pair<Pd,P> Pi; int n,m,k; vector< int > S[2][100010]; map<Pii, bool > used; int main(){ cin >> n >> m >> k; int flg = 0; for ( int i=0;i<k;i++){ int a,b; cin >> a >> b; a--; b--; if (a == 0 && b == 0) flg = 1; S[0][a].push_back(b); S[1][b].push_back(a); } priority_queue<Pi,vector<Pi>,greater<Pi> > que; que.push(Pi(Pd(0,0),P(0,0))); if (flg) que.push(Pi(Pd(1,1),P(0,0))); while (!que.empty()){ Pi p = que.top(); que.pop(); long long int cnt = p.first.first; int vec = p.first.second; int x = p.second.first; int y = p.second.second; if (used[Pii(P(x,y),vec)] != 0) continue ; used[Pii(P(x,y),vec)] = 1; if (vec == 0 && x == n-1) { cout << cnt+ abs ((m-1)-y) << endl; exit (0); } if (vec == 1 && y == m-1){ cout << cnt+ abs ((n-1)-x) << endl; exit (0); } if (vec){ for ( int i=0;i<S[vec][y].size();i++){ int next = S[vec][y][i]; if (used[Pii(Pd(next,y),vec)] != 0) continue ; que.push(Pi(Pd(cnt+ abs (next-x)+1,0),P(next,y))); } } else { for ( int i=0;i<S[vec][x].size();i++){ int next = S[vec][x][i]; if (used[Pii(Pd(x,next),vec)] != 0) continue ; que.push(Pi(Pd(cnt+ abs (next-y)+1,1),P(x,next))); } } } cout << "-1" << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0004 - 現代的な屋敷 |
ユーザー名 | ei1428 |
投稿日時 | 2015-12-22 14:05:19 |
言語 | C++11 |
状態 | Time Limit Exceeded |
得点 | 20 |
ソースコード長 | 1466 Byte |
最大実行時間 | 1000 ms |
最大メモリ使用量 | 212216 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | INPUT1 | 0 / 20 | 01-* |
2 | INPUT2 | 0 / 10 | 02-* |
3 | INPUT3 | 20 / 20 | 03-* |
4 | INPUT4 | 0 / 30 | 04-* |
5 | INPUT5 | 0 / 20 | 05-* |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
01-01.txt | TLE | 1000 ms | 212216 KB |
1
|
||||
01-02.txt | AC | 83 ms | 7180 KB |
1
|
||||
01-03.txt | AC | 132 ms | 9448 KB |
1
|
||||
01-04.txt | WA | 19 ms | 5512 KB |
1
|
||||
01-05.txt | AC | 79 ms | 7832 KB |
1
|
||||
02-01.txt | AC | 21 ms | 5180 KB |
2
|
||||
02-02.txt | AC | 28 ms | 5208 KB |
2
|
||||
02-03.txt | WA | 20 ms | 5220 KB |
2
|
||||
02-04.txt | AC | 20 ms | 5228 KB |
2
|
||||
02-05.txt | AC | 26 ms | 5228 KB |
2
|
||||
03-01.txt | AC | 21 ms | 5228 KB |
3
|
||||
03-02.txt | AC | 28 ms | 5604 KB |
3
|
||||
03-03.txt | AC | 27 ms | 5436 KB |
3
|
||||
03-04.txt | AC | 20 ms | 5448 KB |
3
|
||||
03-05.txt | AC | 27 ms | 5360 KB |
3
|
||||
04-01.txt | AC | 102 ms | 7300 KB |
4
|
||||
04-02.txt | AC | 130 ms | 8680 KB |
4
|
||||
04-03.txt | AC | 126 ms | 9612 KB |
4
|
||||
04-04.txt | TLE | 1000 ms | 54528 KB |
4
|
||||
04-05.txt | AC | 376 ms | 32916 KB |
4
|
||||
04-06.txt | AC | 180 ms | 15912 KB |
4
|
||||
04-07.txt | WA | 513 ms | 35028 KB |
4
|
||||
04-08.txt | AC | 487 ms | 34428 KB |
4
|
||||
05-01.txt | AC | 293 ms | 36608 KB |
5
|
||||
05-02.txt | AC | 410 ms | 36484 KB |
5
|
||||
05-03.txt | TLE | 1000 ms | 54584 KB |
5
|
||||
05-04.txt | AC | 170 ms | 13412 KB |
5
|
||||
05-05.txt | AC | 330 ms | 31796 KB |
5
|
||||
05-06.txt | AC | 184 ms | 15860 KB |
5
|
||||
05-07.txt | AC | 327 ms | 27240 KB |
5
|
||||
05-08.txt | AC | 141 ms | 10644 KB |
5
|