Submission #00035


ソースコード

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include<bits/stdc++.h>
#define INF (1<<29)
#define LLINF (1LL<<59)
#define F first
#define S second
using namespace std;
int h, w, k;
typedef pair < long long, long long >Pii;
typedef pair < Pii, bool > Piib;
typedef struct
{
vector < int >v[2];
int yx[2];
long long mins[2]; //[0]は縦に開いているとき
int num;
} Edge;
Edge edge[200002];
vector < int >H[100005], W[100005];
bool check[2][200002];
main ()
{
cin >> w >> h >> k;
memset (check, 0, sizeof (check));
H[1].push_back (0);
W[1].push_back (0);
edge[0].mins[0] = 0;
edge[0].mins[1] = LLINF;
edge[0].yx[0] = 1;
edge[0].yx[1] = 1;
for (int i = 1; i <= k; i++)
{
int y, x;
cin >> x >> y;
for (int j = 0; j < H[y].size (); j++)
{
edge[i].v[1].push_back (H[y][j]);
edge[H[y][j]].v[1].push_back (i);
}
for (int j = 0; j < W[x].size (); j++)
{
edge[i].v[0].push_back (W[x][j]);
edge[W[x][j]].v[0].push_back (i);
}
H[y].push_back (i);
W[x].push_back (i);
edge[i].num = i;
edge[i].yx[0] = x;
edge[i].yx[1] = y;
edge[i].mins[0] = edge[i].mins[1] = LLINF;
}
priority_queue < Piib, vector < Piib >, greater < Piib > >que;
que.push (Piib (Pii (0, 0), false));
while (!que.empty ())
{
long long nowc = que.top ().F.F;
long long nowp = que.top ().F.S;
bool yoko = que.top ().S;
//cout<<"D"<<nowc<<" "<<nowp<<" "<<yoko<<" "<<edge[nowp].yx[0]<<" "<<edge[nowp].yx[1]<<endl;
que.pop ();
check[yoko][nowp] = true;
if ((!yoko && edge[nowp].yx[0] == w)
|| (yoko && edge[nowp].yx[1] == h))
{
int mines;
if (yoko)
{
mines = w;
}
else
{
mines = h;
}
cout << nowc + llabs (mines - edge[nowp].yx[!yoko]) << endl;
return 0;
}
else
{
for (int i = 0; i < edge[nowp].v[yoko].size (); i++)
{
int nextp = edge[nowp].v[yoko][i];
if (check[!yoko][nextp] == false
&& edge[nextp].mins[!yoko] >
nowc + llabs (edge[nowp].yx[!yoko] -
edge[nextp].yx[!yoko]) + 1)
{
edge[nextp].mins[!yoko] =
nowc + llabs (edge[nowp].yx[!yoko] -
edge[nextp].yx[!yoko]) + 1;
que.
push (Piib
(Pii
(nowc +
llabs (edge[nowp].yx[!yoko] -
edge[nextp].yx[!yoko]) + 1, nextp),
!yoko));
}
}
}
}
cout << -1 << endl;
}

ステータス

項目 データ
問題 0004 - 現代的な屋敷
ユーザー名 ei1417
投稿日時 2015-12-22 15:56:52
言語 C++11
状態 Memory Limit Exceeded
得点 40
ソースコード長 2113 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 20 / 20 05-*

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01-01.txt MLE 1000 ms 262144 KB
1
01-02.txt MLE 1000 ms 262144 KB
1
01-03.txt MLE 1000 ms 262144 KB
1
01-04.txt WA 26 ms 21568 KB
1
01-05.txt MLE 1000 ms 262144 KB
1
02-01.txt AC 22 ms 24728 KB
2
02-02.txt AC 25 ms 24680 KB
2
02-03.txt WA 18 ms 24792 KB
2
02-04.txt AC 21 ms 24784 KB
2
02-05.txt AC 20 ms 24776 KB
2
03-01.txt AC 24 ms 25916 KB
3
03-02.txt AC 29 ms 25052 KB
3
03-03.txt AC 27 ms 24908 KB
3
03-04.txt AC 22 ms 24872 KB
3
03-05.txt AC 29 ms 24980 KB
3
04-01.txt MLE 1000 ms 262144 KB
4
04-02.txt AC 682 ms 136136 KB
4
04-03.txt AC 383 ms 50140 KB
4
04-04.txt AC 572 ms 53584 KB
4
04-05.txt AC 336 ms 46008 KB
4
04-06.txt AC 256 ms 38724 KB
4
04-07.txt WA 335 ms 39532 KB
4
04-08.txt AC 345 ms 47172 KB
4
05-01.txt AC 254 ms 40192 KB
5
05-02.txt AC 261 ms 40144 KB
5
05-03.txt AC 658 ms 59916 KB
5
05-04.txt AC 271 ms 38376 KB
5
05-05.txt AC 314 ms 43500 KB
5
05-06.txt AC 256 ms 38840 KB
5
05-07.txt AC 294 ms 39508 KB
5
05-08.txt AC 285 ms 39760 KB
5