# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20963 |
2017-03-23T05:55:38 Z |
kdh9949 |
Soccer (JOI17_soccer) |
C++14 |
|
1573 ms |
87888 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Bfs{
int x, y;
};
struct Dijk{
int x, y, d; ll md;
bool operator<(const Dijk &oth) const {
return md > oth.md;
}
};
int n, m, k, sx, sy, ex, ey;
ll A, B, C, c[505][505], md[505][505][5];
queue<Bfs> q;
priority_queue<Dijk> pq;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const ll inf = 1e18;
int val(int x, int y){ return x >= 1 && x <= n && y >= 1 && y <= m; }
int main(){
scanf("%d%d%lld%lld%lld%d", &n, &m, &A, &B, &C, &k); n++; m++;
for(int i = 1; i <= n; i++) fill(c[i] + 1, c[i] + m + 1, inf);
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) fill(md[i][j], md[i][j] + 5, inf);
for(int i = 1; i <= k; i++){
int x, y; scanf("%d%d", &x, &y); x++; y++;
c[x][y] = 0; q.push({x, y});
if(i == 1){
sx = x; sy = y;
md[sx][sy][4] = 0;
pq.push({sx, sy, 4, 0});
}
else if(i == k){ ex = x; ey = y; }
}
while(!q.empty()){
Bfs cur = q.front(); q.pop();
for(int i = 0; i < 4; i++){
int nx = cur.x + dx[i], ny = cur.y + dy[i];
if(!val(nx, ny)) continue;
ll nd = c[cur.x][cur.y] + C;
if(c[nx][ny] > nd){
c[nx][ny] = nd;
q.push({nx, ny});
}
}
}
while(!pq.empty()){
Dijk cur = pq.top(); pq.pop();
ll w = cur.d == 4 ? 0 : c[cur.x][cur.y];
for(int i = 0; i < 4; i++){
int nx = cur.x + dx[i], ny = cur.y + dy[i];
ll nd = cur.md + w + C;
if(val(nx, ny) && md[nx][ny][4] > nd){
md[nx][ny][4] = nd;
pq.push({nx, ny, 4, nd});
}
nd = cur.md + (cur.d == i ? 0 : w + B) + A;
if(val(nx, ny) && md[nx][ny][i] > nd){
md[nx][ny][i] = nd;
pq.push({nx, ny, i, nd});
}
}
}
printf("%lld", *min_element(md[ex][ey], md[ex][ey] + 5));
}
Compilation message
soccer.cpp: In function 'int main()':
soccer.cpp:27:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld%lld%lld%d", &n, &m, &A, &B, &C, &k); n++; m++;
^
soccer.cpp:31:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x, y; scanf("%d%d", &x, &y); x++; y++;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
23280 KB |
Output is correct |
2 |
Correct |
0 ms |
13976 KB |
Output is correct |
3 |
Correct |
989 ms |
50924 KB |
Output is correct |
4 |
Correct |
1046 ms |
50924 KB |
Output is correct |
5 |
Correct |
69 ms |
14148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1229 ms |
50948 KB |
Output is correct |
2 |
Correct |
1166 ms |
50968 KB |
Output is correct |
3 |
Correct |
823 ms |
50948 KB |
Output is correct |
4 |
Correct |
809 ms |
50936 KB |
Output is correct |
5 |
Correct |
863 ms |
50968 KB |
Output is correct |
6 |
Correct |
789 ms |
50936 KB |
Output is correct |
7 |
Correct |
1216 ms |
87880 KB |
Output is correct |
8 |
Correct |
1053 ms |
87844 KB |
Output is correct |
9 |
Correct |
1146 ms |
87880 KB |
Output is correct |
10 |
Correct |
86 ms |
23328 KB |
Output is correct |
11 |
Correct |
1213 ms |
87888 KB |
Output is correct |
12 |
Correct |
1209 ms |
87832 KB |
Output is correct |
13 |
Correct |
559 ms |
50936 KB |
Output is correct |
14 |
Correct |
1133 ms |
87884 KB |
Output is correct |
15 |
Correct |
959 ms |
51020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
23280 KB |
Output is correct |
2 |
Correct |
0 ms |
13976 KB |
Output is correct |
3 |
Correct |
989 ms |
50924 KB |
Output is correct |
4 |
Correct |
1046 ms |
50924 KB |
Output is correct |
5 |
Correct |
69 ms |
14148 KB |
Output is correct |
6 |
Correct |
1229 ms |
50948 KB |
Output is correct |
7 |
Correct |
1166 ms |
50968 KB |
Output is correct |
8 |
Correct |
823 ms |
50948 KB |
Output is correct |
9 |
Correct |
809 ms |
50936 KB |
Output is correct |
10 |
Correct |
863 ms |
50968 KB |
Output is correct |
11 |
Correct |
789 ms |
50936 KB |
Output is correct |
12 |
Correct |
1216 ms |
87880 KB |
Output is correct |
13 |
Correct |
1053 ms |
87844 KB |
Output is correct |
14 |
Correct |
1146 ms |
87880 KB |
Output is correct |
15 |
Correct |
86 ms |
23328 KB |
Output is correct |
16 |
Correct |
1213 ms |
87888 KB |
Output is correct |
17 |
Correct |
1209 ms |
87832 KB |
Output is correct |
18 |
Correct |
559 ms |
50936 KB |
Output is correct |
19 |
Correct |
1133 ms |
87884 KB |
Output is correct |
20 |
Correct |
959 ms |
51020 KB |
Output is correct |
21 |
Correct |
89 ms |
15236 KB |
Output is correct |
22 |
Correct |
1553 ms |
50948 KB |
Output is correct |
23 |
Correct |
1443 ms |
50972 KB |
Output is correct |
24 |
Correct |
1573 ms |
32680 KB |
Output is correct |
25 |
Correct |
1469 ms |
50952 KB |
Output is correct |
26 |
Correct |
1296 ms |
51112 KB |
Output is correct |
27 |
Correct |
216 ms |
15032 KB |
Output is correct |
28 |
Correct |
369 ms |
15164 KB |
Output is correct |
29 |
Correct |
1036 ms |
33360 KB |
Output is correct |
30 |
Correct |
669 ms |
19516 KB |
Output is correct |
31 |
Correct |
1373 ms |
87880 KB |
Output is correct |
32 |
Correct |
1546 ms |
51772 KB |
Output is correct |
33 |
Correct |
1033 ms |
50928 KB |
Output is correct |
34 |
Correct |
1546 ms |
51020 KB |
Output is correct |
35 |
Correct |
236 ms |
14900 KB |
Output is correct |