Submission #00017
ソースコード
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; 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(); 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:08:57 |
言語 | C++11 |
状態 | Memory Limit Exceeded |
得点 | 20 |
ソースコード長 | 1458 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 | 86 ms | 7128 KB |
1
|
||||
01-03.txt | AC | 141 ms | 9896 KB |
1
|
||||
01-04.txt | WA | 23 ms | 5592 KB |
1
|
||||
01-05.txt | AC | 81 ms | 7824 KB |
1
|
||||
02-01.txt | AC | 19 ms | 5172 KB |
2
|
||||
02-02.txt | AC | 19 ms | 5196 KB |
2
|
||||
02-03.txt | WA | 20 ms | 5200 KB |
2
|
||||
02-04.txt | AC | 21 ms | 5196 KB |
2
|
||||
02-05.txt | AC | 26 ms | 5064 KB |
2
|
||||
03-01.txt | AC | 20 ms | 5196 KB |
3
|
||||
03-02.txt | AC | 28 ms | 5572 KB |
3
|
||||
03-03.txt | AC | 20 ms | 5468 KB |
3
|
||||
03-04.txt | AC | 19 ms | 5432 KB |
3
|
||||
03-05.txt | AC | 23 ms | 5556 KB |
3
|
||||
04-01.txt | AC | 117 ms | 7316 KB |
4
|
||||
04-02.txt | AC | 119 ms | 8692 KB |
4
|
||||
04-03.txt | AC | 127 ms | 9500 KB |
4
|
||||
04-04.txt | TLE | 1000 ms | 65864 KB |
4
|
||||
04-05.txt | AC | 405 ms | 38340 KB |
4
|
||||
04-06.txt | AC | 174 ms | 16860 KB |
4
|
||||
04-07.txt | WA | 525 ms | 40788 KB |
4
|
||||
04-08.txt | AC | 492 ms | 41484 KB |
4
|
||||
05-01.txt | AC | 262 ms | 42664 KB |
5
|
||||
05-02.txt | AC | 336 ms | 42696 KB |
5
|
||||
05-03.txt | TLE | 1000 ms | 67152 KB |
5
|
||||
05-04.txt | AC | 168 ms | 14272 KB |
5
|
||||
05-05.txt | AC | 348 ms | 37188 KB |
5
|
||||
05-06.txt | AC | 181 ms | 17320 KB |
5
|
||||
05-07.txt | AC | 325 ms | 31296 KB |
5
|
||||
05-08.txt | AC | 165 ms | 10780 KB |
5
|