# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
97490 |
2019-02-16T11:57:08 Z |
easrui |
None (JOI16_skating) |
C++14 |
|
3000 ms |
71056 KB |
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
const int MAX = 1005;
typedef pair<int,int> pii;
typedef pair<int,pii> ppi;
int R,C,sx,sy,ex,ey,cnt,dis[MAX][MAX],l[MAX][MAX],r[MAX][MAX],u[MAX][MAX],d[MAX][MAX];
bool init[MAX][MAX];
char c;
priority_queue<ppi> PQ;
int main()
{
cin >> R >> C;
for(int i=1; i<=R; i++){
for(int j=1; j<=C; j++){
cin >> c;
if(c=='.') init[i][j] = 1;
dis[i][j] = 1e6;
}
}
cin >> sy >> sx >> ey >> ex;
for(int i=1; i<=R; i++){
for(int j=1; j<=C; j++){
if(init[i][j]) l[i][j] = cnt;
else cnt = j;
}
for(int j=C; j>=1; j--){
if(init[i][j]) r[i][j] = cnt;
else cnt = j;
}
}
for(int j=1; j<=C; j++){
for(int i=1; i<=R; i++){
if(init[i][j]) u[i][j] = cnt;
else cnt = i;
}
for(int i=R; i>=1; i--){
if(init[i][j]) d[i][j] = cnt;
else cnt = i;
}
}
dis[sy][sx] = 0;
int D,y,x,v1,v2;
PQ.push(ppi(0,pii(sy,sx)));
while(!PQ.empty()){
D = -PQ.top().va;
y = PQ.top().vb.va;
x = PQ.top().vb.vb;
PQ.pop();
if(D>dis[y][x]) continue;
v1 = l[y][x]+1;
v2 = x-1;
cnt = 1;
while(v1<=v2){
if(cnt%2){
if(dis[y][v1]>D+cnt){
dis[y][v1] = D+cnt;
PQ.push(ppi(-D-cnt,pii(y,v1)));
}
v1++;
}
else{
if(dis[y][v2]>D+cnt){
dis[y][v2] = D+cnt;
PQ.push(ppi(-D-cnt,pii(y,v2)));
}
v2--;
}
cnt++;
}
v1 = x+1;
v2 = r[y][x]-1;
cnt = 1;
while(v1<=v2){
if(cnt%2){
if(dis[y][v2]>D+cnt){
dis[y][v2] = D+cnt;
PQ.push(ppi(-D-cnt,pii(y,v2)));
}
v2--;
}
else{
if(dis[y][v1]>D+cnt){
dis[y][v1] = D+cnt;
PQ.push(ppi(-D-cnt,pii(y,v1)));
}
v1++;
}
cnt++;
}
v1 = u[y][x]+1;
v2 = y-1;
cnt = 1;
while(v1<=v2){
if(cnt%2){
if(dis[v1][x]>D+cnt){
dis[v1][x] = D+cnt;
PQ.push(ppi(-D-cnt,pii(v1,x)));
}
v1++;
}
else{
if(dis[v2][x]>D+cnt){
dis[v2][x] = D+cnt;
PQ.push(ppi(-D-cnt,pii(v2,x)));
}
v2--;
}
cnt++;
}
v1 = y+1;
v2 = d[y][x]-1;
cnt = 1;
while(v1<=v2){
if(cnt%2){
if(dis[v2][x]>D+cnt){
dis[v2][x] = D+cnt;
PQ.push(ppi(-D-cnt,pii(v2,x)));
}
v2--;
}
else{
if(dis[v1][x]>D+cnt){
dis[v1][x] = D+cnt;
PQ.push(ppi(-D-cnt,pii(v1,x)));
}
v1++;
}
cnt++;
}
}
if(dis[ey][ex]==1e6) cout << -1;
else cout << dis[ey][ex];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
88 ms |
5372 KB |
Output is correct |
12 |
Correct |
73 ms |
6136 KB |
Output is correct |
13 |
Correct |
55 ms |
6092 KB |
Output is correct |
14 |
Correct |
20 ms |
4608 KB |
Output is correct |
15 |
Correct |
10 ms |
4480 KB |
Output is correct |
16 |
Correct |
41 ms |
5372 KB |
Output is correct |
17 |
Correct |
22 ms |
4480 KB |
Output is correct |
18 |
Correct |
17 ms |
4480 KB |
Output is correct |
19 |
Correct |
20 ms |
4608 KB |
Output is correct |
20 |
Correct |
44 ms |
4800 KB |
Output is correct |
21 |
Correct |
11 ms |
4480 KB |
Output is correct |
22 |
Correct |
18 ms |
4480 KB |
Output is correct |
23 |
Correct |
18 ms |
4480 KB |
Output is correct |
24 |
Correct |
31 ms |
5048 KB |
Output is correct |
25 |
Correct |
13 ms |
4480 KB |
Output is correct |
26 |
Correct |
13 ms |
4480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
88 ms |
5372 KB |
Output is correct |
12 |
Correct |
73 ms |
6136 KB |
Output is correct |
13 |
Correct |
55 ms |
6092 KB |
Output is correct |
14 |
Correct |
20 ms |
4608 KB |
Output is correct |
15 |
Correct |
10 ms |
4480 KB |
Output is correct |
16 |
Correct |
41 ms |
5372 KB |
Output is correct |
17 |
Correct |
22 ms |
4480 KB |
Output is correct |
18 |
Correct |
17 ms |
4480 KB |
Output is correct |
19 |
Correct |
20 ms |
4608 KB |
Output is correct |
20 |
Correct |
44 ms |
4800 KB |
Output is correct |
21 |
Correct |
11 ms |
4480 KB |
Output is correct |
22 |
Correct |
18 ms |
4480 KB |
Output is correct |
23 |
Correct |
18 ms |
4480 KB |
Output is correct |
24 |
Correct |
31 ms |
5048 KB |
Output is correct |
25 |
Correct |
13 ms |
4480 KB |
Output is correct |
26 |
Correct |
13 ms |
4480 KB |
Output is correct |
27 |
Execution timed out |
3034 ms |
71056 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |