Submission #00022
ソースコード
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 lld; //typedef pair<int,int> P; typedef pair<lld,lld> P; typedef pair<P,lld> Pii; typedef pair<P,P> Pi; lld 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(); lld cnt = p.first.first; lld vec = p.first.second; lld x = p.second.first; lld 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+llabs((m-1)-y) << endl; exit (0); } if (vec == 1 && y == m-1){ cout << cnt+llabs((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+llabs(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+llabs(next-y)+1,1),P(x,next))); } } } cout << "-1" << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0004 - 現代的な屋敷 |
ユーザー名 | ei1428 |
投稿日時 | 2015-12-22 14:34:26 |
言語 | C++11 |
状態 | Memory Limit Exceeded |
得点 | 20 |
ソースコード長 | 1460 Byte |
最大実行時間 | 1000 ms |
最大メモリ使用量 | 262144 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 | MLE | 1000 ms | 262144 KB |
1
|
||||
01-02.txt | AC | 82 ms | 7172 KB |
1
|
||||
01-03.txt | MLE | 1000 ms | 262144 KB |
1
|
||||
01-04.txt | WA | 24 ms | 5716 KB |
1
|
||||
01-05.txt | AC | 83 ms | 7788 KB |
1
|
||||
02-01.txt | AC | 27 ms | 5136 KB |
2
|
||||
02-02.txt | AC | 17 ms | 5160 KB |
2
|
||||
02-03.txt | WA | 18 ms | 5016 KB |
2
|
||||
02-04.txt | AC | 18 ms | 5144 KB |
2
|
||||
02-05.txt | AC | 20 ms | 5132 KB |
2
|
||||
03-01.txt | AC | 20 ms | 5260 KB |
3
|
||||
03-02.txt | AC | 26 ms | 5632 KB |
3
|
||||
03-03.txt | AC | 23 ms | 5480 KB |
3
|
||||
03-04.txt | AC | 27 ms | 5448 KB |
3
|
||||
03-05.txt | AC | 23 ms | 5448 KB |
3
|
||||
04-01.txt | AC | 99 ms | 7208 KB |
4
|
||||
04-02.txt | AC | 114 ms | 8712 KB |
4
|
||||
04-03.txt | AC | 127 ms | 9516 KB |
4
|
||||
04-04.txt | TLE | 1000 ms | 62560 KB |
4
|
||||
04-05.txt | AC | 460 ms | 40764 KB |
4
|
||||
04-06.txt | AC | 186 ms | 17112 KB |
4
|
||||
04-07.txt | WA | 693 ms | 42916 KB |
4
|
||||
04-08.txt | AC | 599 ms | 51544 KB |
4
|
||||
05-01.txt | AC | 238 ms | 42876 KB |
5
|
||||
05-02.txt | AC | 302 ms | 42900 KB |
5
|
||||
05-03.txt | TLE | 1000 ms | 98832 KB |
5
|
||||
05-04.txt | AC | 180 ms | 14204 KB |
5
|
||||
05-05.txt | AC | 386 ms | 35748 KB |
5
|
||||
05-06.txt | AC | 175 ms | 17208 KB |
5
|
||||
05-07.txt | AC | 368 ms | 33584 KB |
5
|
||||
05-08.txt | AC | 129 ms | 10916 KB |
5
|