Submission #00012
ソースコード
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 | #include<bits/stdc++.h> using namespace std; typedef pair< int , int > P; typedef pair<P, int > Pii; typedef pair<P,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(P(0,0),P(0,0))); if (flg) que.push(Pi(P(1,1),P(0,0))); while (!que.empty()){ Pi p = que.top(); que.pop(); 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(P(next,y),vec)] != 0) continue ; que.push(Pi(P(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(P(x,next),vec)] != 0) continue ; que.push(Pi(P(cnt+ abs (next-y)+1,1),P(x,next))); } } } cout << "-1" << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0004 - 現代的な屋敷 |
ユーザー名 | ei1428 |
投稿日時 | 2015-12-22 14:01:33 |
言語 | C++11 |
状態 | Time Limit Exceeded |
得点 | 20 |
ソースコード長 | 1394 Byte |
最大実行時間 | 1000 ms |
最大メモリ使用量 | 147380 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 | 147380 KB |
1
|
||||
01-02.txt | AC | 85 ms | 8368 KB |
1
|
||||
01-03.txt | AC | 136 ms | 10124 KB |
1
|
||||
01-04.txt | WA | 24 ms | 6820 KB |
1
|
||||
01-05.txt | AC | 86 ms | 9288 KB |
1
|
||||
02-01.txt | AC | 25 ms | 6508 KB |
2
|
||||
02-02.txt | AC | 26 ms | 6536 KB |
2
|
||||
02-03.txt | WA | 22 ms | 6420 KB |
2
|
||||
02-04.txt | AC | 18 ms | 6552 KB |
2
|
||||
02-05.txt | AC | 22 ms | 6676 KB |
2
|
||||
03-01.txt | AC | 24 ms | 6552 KB |
3
|
||||
03-02.txt | AC | 23 ms | 6920 KB |
3
|
||||
03-03.txt | AC | 22 ms | 6900 KB |
3
|
||||
03-04.txt | AC | 22 ms | 6780 KB |
3
|
||||
03-05.txt | AC | 27 ms | 6820 KB |
3
|
||||
04-01.txt | AC | 105 ms | 8504 KB |
4
|
||||
04-02.txt | AC | 116 ms | 10008 KB |
4
|
||||
04-03.txt | AC | 125 ms | 10816 KB |
4
|
||||
04-04.txt | TLE | 1000 ms | 46576 KB |
4
|
||||
04-05.txt | AC | 373 ms | 32784 KB |
4
|
||||
04-06.txt | AC | 170 ms | 16884 KB |
4
|
||||
04-07.txt | WA | 510 ms | 35820 KB |
4
|
||||
04-08.txt | AC | 451 ms | 34860 KB |
4
|
||||
05-01.txt | WA | 294 ms | 37780 KB |
5
|
||||
05-02.txt | WA | 384 ms | 37788 KB |
5
|
||||
05-03.txt | TLE | 1000 ms | 47624 KB |
5
|
||||
05-04.txt | AC | 175 ms | 14828 KB |
5
|
||||
05-05.txt | AC | 339 ms | 30612 KB |
5
|
||||
05-06.txt | AC | 175 ms | 17236 KB |
5
|
||||
05-07.txt | AC | 319 ms | 28308 KB |
5
|
||||
05-08.txt | AC | 131 ms | 11952 KB |
5
|