# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259674 |
2020-08-08T09:07:57 Z |
arnold518 |
None (JOI16_skating) |
C++14 |
|
297 ms |
28268 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
const ll INF = 1e18;
int N, M;
char S[MAXN+10][MAXN+10];
int L[MAXN+10][MAXN+10], R[MAXN+10][MAXN+10], U[MAXN+10][MAXN+10], D[MAXN+10][MAXN+10];
ll dist[MAXN+10][MAXN+10];
pii P, Q;
struct Queue
{
int y, x; ll w;
bool operator < (const Queue &p) const { return w>p.w; }
};
priority_queue<Queue> PQ;
void enqueue(Queue now)
{
if(dist[now.y][now.x]<=now.w) return;
dist[now.y][now.x]=now.w;
PQ.push(now);
}
int main()
{
scanf("%d%d", &N, &M);
for(int i=1; i<=N; i++) scanf("%s", S[i]+1);
scanf("%d%d%d%d", &P.first, &P.second, &Q.first, &Q.second);
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++)
{
if(S[i][j]=='#') U[i][j]=i;
else U[i][j]=U[i-1][j];
if(S[i][j]=='#') L[i][j]=j;
else L[i][j]=L[i][j-1];
}
for(int i=N; i>=1; i--) for(int j=M; j>=1; j--)
{
if(S[i][j]=='#') D[i][j]=i;
else D[i][j]=D[i+1][j];
if(S[i][j]=='#') R[i][j]=j;
else R[i][j]=R[i][j+1];
}
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++)
{
L[i][j]++; R[i][j]--;
U[i][j]++; D[i][j]--;
}
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) dist[i][j]=INF;
enqueue({P.first, P.second, 0});
enqueue({P.first, P.second, 0});
while(!PQ.empty())
{
Queue now=PQ.top(); PQ.pop();
if(dist[now.y][now.x]!=now.w) continue;
enqueue({now.y, L[now.y][now.x], now.w+1});
enqueue({now.y, R[now.y][now.x], now.w+1});
if(U[now.y][now.x]<=now.y-1) enqueue({now.y-1, now.x, now.w+2});
if(D[now.y][now.x]>=now.y+1) enqueue({now.y+1, now.x, now.w+2});
enqueue({U[now.y][now.x], now.x, now.w+1});
enqueue({D[now.y][now.x], now.x, now.w+1});
if(L[now.y][now.x]<=now.x-1) enqueue({now.y, now.x-1, now.w+2});
if(R[now.y][now.x]>=now.x+1) enqueue({now.y, now.x+1, now.w+2});
}
ll ans=dist[Q.first][Q.second];
if(ans==INF) ans=-1;
printf("%lld\n", ans);
}
Compilation message
skating.cpp: In function 'int main()':
skating.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
skating.cpp:34:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<=N; i++) scanf("%s", S[i]+1);
~~~~~^~~~~~~~~~~~~~
skating.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &P.first, &P.second, &Q.first, &Q.second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
7 ms |
4864 KB |
Output is correct |
12 |
Correct |
7 ms |
4992 KB |
Output is correct |
13 |
Correct |
8 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
4864 KB |
Output is correct |
15 |
Correct |
3 ms |
4864 KB |
Output is correct |
16 |
Correct |
10 ms |
5120 KB |
Output is correct |
17 |
Correct |
6 ms |
4864 KB |
Output is correct |
18 |
Correct |
5 ms |
4864 KB |
Output is correct |
19 |
Correct |
9 ms |
4992 KB |
Output is correct |
20 |
Correct |
9 ms |
4608 KB |
Output is correct |
21 |
Correct |
5 ms |
4864 KB |
Output is correct |
22 |
Correct |
3 ms |
4864 KB |
Output is correct |
23 |
Correct |
7 ms |
4864 KB |
Output is correct |
24 |
Correct |
6 ms |
4864 KB |
Output is correct |
25 |
Correct |
6 ms |
4864 KB |
Output is correct |
26 |
Correct |
6 ms |
4864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
7 ms |
4864 KB |
Output is correct |
12 |
Correct |
7 ms |
4992 KB |
Output is correct |
13 |
Correct |
8 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
4864 KB |
Output is correct |
15 |
Correct |
3 ms |
4864 KB |
Output is correct |
16 |
Correct |
10 ms |
5120 KB |
Output is correct |
17 |
Correct |
6 ms |
4864 KB |
Output is correct |
18 |
Correct |
5 ms |
4864 KB |
Output is correct |
19 |
Correct |
9 ms |
4992 KB |
Output is correct |
20 |
Correct |
9 ms |
4608 KB |
Output is correct |
21 |
Correct |
5 ms |
4864 KB |
Output is correct |
22 |
Correct |
3 ms |
4864 KB |
Output is correct |
23 |
Correct |
7 ms |
4864 KB |
Output is correct |
24 |
Correct |
6 ms |
4864 KB |
Output is correct |
25 |
Correct |
6 ms |
4864 KB |
Output is correct |
26 |
Correct |
6 ms |
4864 KB |
Output is correct |
27 |
Correct |
218 ms |
26616 KB |
Output is correct |
28 |
Correct |
254 ms |
27352 KB |
Output is correct |
29 |
Correct |
297 ms |
28268 KB |
Output is correct |
30 |
Correct |
161 ms |
26740 KB |
Output is correct |
31 |
Correct |
31 ms |
25976 KB |
Output is correct |
32 |
Correct |
168 ms |
26156 KB |
Output is correct |
33 |
Correct |
33 ms |
13052 KB |
Output is correct |
34 |
Correct |
59 ms |
26104 KB |
Output is correct |
35 |
Correct |
134 ms |
26488 KB |
Output is correct |
36 |
Correct |
107 ms |
26488 KB |
Output is correct |
37 |
Correct |
49 ms |
26104 KB |
Output is correct |
38 |
Correct |
260 ms |
27248 KB |
Output is correct |
39 |
Correct |
54 ms |
25984 KB |
Output is correct |
40 |
Correct |
31 ms |
25984 KB |
Output is correct |