# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
87863 |
2018-12-02T22:48:16 Z |
KCSC |
Soccer (JOI17_soccer) |
C++14 |
|
642 ms |
23584 KB |
#include <bits/stdc++.h>
using namespace std;
const int DIM = 505;
const int dx[5] = {0, -1, 0, 1, 0};
const int dy[5] = {0, 0, 1, 0, -1};
long long dp[DIM][DIM][5], dst[DIM][DIM];
pair<int, int> pos[DIM * DIM];
deque<pair<int, int>> que;
priority_queue<pair<long long, tuple<int, int, int>>,
vector<pair<long long, tuple<int, int, int>>>,
greater<pair<long long, tuple<int, int, int>>>> prq;
int main(void) {
#ifdef HOME
freopen("soccer.in", "r", stdin);
freopen("soccer.out", "w", stdout);
#endif
int n, m, a, b, c, k;
cin >> n >> m >> a >> b >> c >> k;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
dst[i][j] = 1LL << 60;
for (int k = 0; k <= 4; ++k) {
dp[i][j][k] = 1LL << 60; } } }
for (int i = 1; i <= k; ++i) {
int x, y; cin >> x >> y; dst[x][y] = 0;
pos[i] = make_pair(x, y); }
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
if (dst[i][j] == 0) {
que.push_back(make_pair(i, j)); } } }
while (que.size()) {
int x, y; tie(x, y) = que.front(); que.pop_front();
for (int d = 1; d <= 4; ++d) {
int xx = x + dx[d], yy = y + dy[d];
if (xx >= 0 and xx <= n and yy >= 0 and yy <= m and dst[xx][yy] == 1LL << 60) {
dst[xx][yy] = dst[x][y] + c; que.push_back(make_pair(xx, yy)); } } }
dp[pos[1].first][pos[1].second][0] = 0;
prq.push(make_pair(0, make_tuple(pos[1].first, pos[1].second, 0)));
while (prq.size()) {
long long ds; int x, y, z;
ds = prq.top().first; tie(x, y, z) = prq.top().second; prq.pop();
if (dp[x][y][z] != ds) {
continue; }
if (z == 0) {
for (int d = 1; d <= 4; ++d) {
if (dp[x][y][d] > dp[x][y][0] + b) {
dp[x][y][d] = dp[x][y][0] + b; prq.push(make_pair(dp[x][y][d], make_tuple(x, y, d))); }
int xx = x + dx[d], yy = y + dy[d];
if (xx >= 0 and xx <= n and yy >= 0 and yy <= m and dp[xx][yy][0] > dp[x][y][0] + c) {
dp[xx][yy][0] = dp[x][y][0] + c; prq.push(make_pair(dp[xx][yy][0], make_tuple(xx, yy, 0))); } } }
else {
if (dp[x][y][0] > dp[x][y][z] + dst[x][y]) {
dp[x][y][0] = dp[x][y][z] + dst[x][y]; prq.push(make_pair(dp[x][y][0], make_tuple(x, y, 0))); }
int xx = x + dx[z], yy = y + dy[z];
if (xx >= 0 and xx <= n and yy >= 0 and yy <= m and dp[xx][yy][z] > dp[x][y][z] + a) {
dp[xx][yy][z] = dp[x][y][z] + a; prq.push(make_pair(dp[xx][yy][z], make_tuple(xx, yy, z))); } } }
cout << dp[pos[k].first][pos[k].second][0] << endl;
return 0; }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
6764 KB |
Output is correct |
2 |
Correct |
2 ms |
6764 KB |
Output is correct |
3 |
Correct |
421 ms |
18608 KB |
Output is correct |
4 |
Correct |
409 ms |
18608 KB |
Output is correct |
5 |
Correct |
87 ms |
18608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
471 ms |
18824 KB |
Output is correct |
2 |
Correct |
440 ms |
18824 KB |
Output is correct |
3 |
Correct |
336 ms |
18824 KB |
Output is correct |
4 |
Correct |
323 ms |
18824 KB |
Output is correct |
5 |
Correct |
333 ms |
18824 KB |
Output is correct |
6 |
Correct |
348 ms |
18956 KB |
Output is correct |
7 |
Correct |
434 ms |
18956 KB |
Output is correct |
8 |
Correct |
418 ms |
18956 KB |
Output is correct |
9 |
Correct |
483 ms |
19056 KB |
Output is correct |
10 |
Correct |
70 ms |
19056 KB |
Output is correct |
11 |
Correct |
429 ms |
19172 KB |
Output is correct |
12 |
Correct |
433 ms |
19172 KB |
Output is correct |
13 |
Correct |
264 ms |
19172 KB |
Output is correct |
14 |
Correct |
495 ms |
19204 KB |
Output is correct |
15 |
Correct |
385 ms |
19204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
6764 KB |
Output is correct |
2 |
Correct |
2 ms |
6764 KB |
Output is correct |
3 |
Correct |
421 ms |
18608 KB |
Output is correct |
4 |
Correct |
409 ms |
18608 KB |
Output is correct |
5 |
Correct |
87 ms |
18608 KB |
Output is correct |
6 |
Correct |
471 ms |
18824 KB |
Output is correct |
7 |
Correct |
440 ms |
18824 KB |
Output is correct |
8 |
Correct |
336 ms |
18824 KB |
Output is correct |
9 |
Correct |
323 ms |
18824 KB |
Output is correct |
10 |
Correct |
333 ms |
18824 KB |
Output is correct |
11 |
Correct |
348 ms |
18956 KB |
Output is correct |
12 |
Correct |
434 ms |
18956 KB |
Output is correct |
13 |
Correct |
418 ms |
18956 KB |
Output is correct |
14 |
Correct |
483 ms |
19056 KB |
Output is correct |
15 |
Correct |
70 ms |
19056 KB |
Output is correct |
16 |
Correct |
429 ms |
19172 KB |
Output is correct |
17 |
Correct |
433 ms |
19172 KB |
Output is correct |
18 |
Correct |
264 ms |
19172 KB |
Output is correct |
19 |
Correct |
495 ms |
19204 KB |
Output is correct |
20 |
Correct |
385 ms |
19204 KB |
Output is correct |
21 |
Correct |
119 ms |
19204 KB |
Output is correct |
22 |
Correct |
621 ms |
19204 KB |
Output is correct |
23 |
Correct |
565 ms |
19204 KB |
Output is correct |
24 |
Correct |
642 ms |
19204 KB |
Output is correct |
25 |
Correct |
475 ms |
19364 KB |
Output is correct |
26 |
Correct |
526 ms |
19420 KB |
Output is correct |
27 |
Correct |
360 ms |
19420 KB |
Output is correct |
28 |
Correct |
355 ms |
19420 KB |
Output is correct |
29 |
Correct |
521 ms |
19420 KB |
Output is correct |
30 |
Correct |
318 ms |
19420 KB |
Output is correct |
31 |
Correct |
490 ms |
21968 KB |
Output is correct |
32 |
Correct |
628 ms |
23584 KB |
Output is correct |
33 |
Correct |
375 ms |
23584 KB |
Output is correct |
34 |
Correct |
599 ms |
23584 KB |
Output is correct |
35 |
Correct |
307 ms |
23584 KB |
Output is correct |