#include<bits/stdc++.h>
using namespace std;
int A, B, C, H, W, N, d[509][509], x[100009], y[100009];
long long minD[5][509][509];
const long long INF = 1LL << 60;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
queue < pair < int, int > > cc;
void read ()
{
scanf ("%d %d", &H, &W), H ++, W ++;
scanf ("%d %d %d", &A, &B, &C);
scanf ("%d", &N);
for (int i=1; i<=H; i++)
for (int j=1; j<=W; j++)
d[i][j] = -1;
for (int i=1; i<=N; i++)
{
scanf ("%d %d", &x[i], &y[i]), x[i] ++, y[i] ++;
d[x[i]][y[i]] = 0, cc.push ({x[i], y[i]});
}
while (!cc.empty ())
{
auto curr = cc.front ();
cc.pop ();
for (int k=0; k<4; k++)
{
int nx = curr.first + dx[k], ny = curr.second + dy[k];
if (d[nx][ny] == -1)
d[nx][ny] = d[curr.first][curr.second] + 1, cc.push ({nx, ny});
}
}
}
priority_queue < pair < long long, pair < int, pair < int, int > > > > PQ;
void update (int p, int i, int j, long long d)
{
if (i < 1 || j < 1 || i > H || j > W) return ;
if (d < minD[p][i][j])
minD[p][i][j] = d, PQ.push ({-d, {p, {i, j}}});
}
int modul (int x)
{
if (x < 0) return -x;
return x;
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
read ();
for (int p=0; p<5; p++)
for (int i=1; i<=H; i++)
for (int j=1; j<=W; j++)
minD[p][i][j] = INF;
PQ.push ({0, {4, {x[1], y[1]}}}), minD[4][x[1]][y[1]] = 0;
while (!PQ.empty ())
{
auto curr = PQ.top ();
PQ.pop ();
int i = curr.second.second.first, j = curr.second.second.second, p = curr.second.first;
if (minD[p][i][j] != -curr.first) continue;
if (p == 4)
{
for (int k=0; k<4; k++)
{
update (4, i + dx[k], j + dy[k], minD[4][i][j] + C);
update (k, i + dx[k], j + dy[k], minD[4][i][j] + A + B);
}
}
else
{
update (4, i, j, minD[p][i][j] + 1LL * C * d[i][j]);
update (p, i + dx[p], j + dy[p], minD[p][i][j] + A);
}
}
printf ("%lld\n", minD[4][x[N]][y[N]]);
return 0;
}
Compilation message
soccer.cpp: In function 'void read()':
soccer.cpp:14:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &H, &W), H ++, W ++;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
soccer.cpp:15:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d %d", &A, &B, &C);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:16:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &N);
~~~~~~^~~~~~~~~~
soccer.cpp:22:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &x[i], &y[i]), x[i] ++, y[i] ++;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
8564 KB |
Output is correct |
2 |
Correct |
3 ms |
8564 KB |
Output is correct |
3 |
Correct |
631 ms |
17884 KB |
Output is correct |
4 |
Correct |
723 ms |
17896 KB |
Output is correct |
5 |
Correct |
164 ms |
17896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
794 ms |
17896 KB |
Output is correct |
2 |
Correct |
788 ms |
18032 KB |
Output is correct |
3 |
Correct |
561 ms |
18032 KB |
Output is correct |
4 |
Correct |
553 ms |
18032 KB |
Output is correct |
5 |
Correct |
593 ms |
18088 KB |
Output is correct |
6 |
Correct |
553 ms |
18088 KB |
Output is correct |
7 |
Correct |
668 ms |
18088 KB |
Output is correct |
8 |
Correct |
646 ms |
18088 KB |
Output is correct |
9 |
Correct |
739 ms |
18088 KB |
Output is correct |
10 |
Correct |
129 ms |
18088 KB |
Output is correct |
11 |
Correct |
674 ms |
18112 KB |
Output is correct |
12 |
Correct |
752 ms |
18112 KB |
Output is correct |
13 |
Correct |
444 ms |
18112 KB |
Output is correct |
14 |
Correct |
828 ms |
18136 KB |
Output is correct |
15 |
Correct |
594 ms |
18272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
8564 KB |
Output is correct |
2 |
Correct |
3 ms |
8564 KB |
Output is correct |
3 |
Correct |
631 ms |
17884 KB |
Output is correct |
4 |
Correct |
723 ms |
17896 KB |
Output is correct |
5 |
Correct |
164 ms |
17896 KB |
Output is correct |
6 |
Correct |
794 ms |
17896 KB |
Output is correct |
7 |
Correct |
788 ms |
18032 KB |
Output is correct |
8 |
Correct |
561 ms |
18032 KB |
Output is correct |
9 |
Correct |
553 ms |
18032 KB |
Output is correct |
10 |
Correct |
593 ms |
18088 KB |
Output is correct |
11 |
Correct |
553 ms |
18088 KB |
Output is correct |
12 |
Correct |
668 ms |
18088 KB |
Output is correct |
13 |
Correct |
646 ms |
18088 KB |
Output is correct |
14 |
Correct |
739 ms |
18088 KB |
Output is correct |
15 |
Correct |
129 ms |
18088 KB |
Output is correct |
16 |
Correct |
674 ms |
18112 KB |
Output is correct |
17 |
Correct |
752 ms |
18112 KB |
Output is correct |
18 |
Correct |
444 ms |
18112 KB |
Output is correct |
19 |
Correct |
828 ms |
18136 KB |
Output is correct |
20 |
Correct |
594 ms |
18272 KB |
Output is correct |
21 |
Correct |
196 ms |
18272 KB |
Output is correct |
22 |
Correct |
926 ms |
18272 KB |
Output is correct |
23 |
Correct |
802 ms |
18272 KB |
Output is correct |
24 |
Correct |
967 ms |
18272 KB |
Output is correct |
25 |
Correct |
702 ms |
18308 KB |
Output is correct |
26 |
Correct |
816 ms |
18552 KB |
Output is correct |
27 |
Correct |
429 ms |
18552 KB |
Output is correct |
28 |
Correct |
510 ms |
18552 KB |
Output is correct |
29 |
Correct |
852 ms |
18756 KB |
Output is correct |
30 |
Correct |
475 ms |
18756 KB |
Output is correct |
31 |
Correct |
780 ms |
21040 KB |
Output is correct |
32 |
Correct |
884 ms |
23264 KB |
Output is correct |
33 |
Correct |
673 ms |
23264 KB |
Output is correct |
34 |
Correct |
905 ms |
23264 KB |
Output is correct |
35 |
Correct |
433 ms |
23264 KB |
Output is correct |