# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
205611 |
2020-02-29T10:02:54 Z |
Kastanda |
Soccer (JOI17_soccer) |
C++11 |
|
537 ms |
19076 KB |
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 505, MXN = 100005;
int n, m, k, A, B, C, P[N][N];
pair < int , int > At[MXN];
long long D[N][N][5];
int gx[] = {-1, 1, 0, 0};
int gy[] = {0, 0, -1, 1};
int main()
{
scanf("%d%d", &n, &m);
scanf("%d%d%d", &A, &B, &C);
scanf("%d", &k);
memset(P, 63, sizeof(P));
queue < pair < int , int > > qu;
for (int i = 1; i <= k; i ++)
{
scanf("%d%d", &At[i].first, &At[i].second);
P[At[i].first][At[i].second] = 0;
if (i < k) qu.push({At[i].first, At[i].second});
}
while (qu.size())
{
int a = qu.front().first;
int b = qu.front().second;
qu.pop();
for (int h = 0; h < 4; h ++)
{
int ta = a + gx[h];
int tb = b + gy[h];
if (ta >= 0 && ta <= n && tb >= 0 && tb <= m && P[ta][tb] > P[a][b] + 1)
P[ta][tb] = P[a][b] + 1, qu.push({ta, tb});
}
}
P[At[k].first][At[k].second] = 0;
memset(D, 63, sizeof(D));
priority_queue < tuple < long long , int , int , int > > Pq;
auto Relax = [&] (int a, int b, int w, long long d) {
if (D[a][b][w] > d) {
D[a][b][w] = d;
Pq.push(make_tuple(-d, a, b, w));
}
};
Relax(At[1].first, At[1].second, 4, 0);
while (Pq.size())
{
long long d;
int a, b, w;
tie(d, a, b, w) = Pq.top();
Pq.pop(); d = -d;
if (d > D[a][b][w])
continue;
if (w < 4)
{
int ta = a + gx[w], tb = b + gy[w];
if (ta >= 0 && ta <= n && tb >= 0 && tb <= m)
Relax(ta, tb, w, d + A);
Relax(a, b, 4, d + 1LL * P[a][b] * C);
}
else
{
for (int h = 0; h < 4; h ++)
{
int ta = a + gx[h], tb = b + gy[h];
if (ta >= 0 && ta <= n && tb >= 0 && tb <= m)
Relax(ta, tb, 4, d + C);
Relax(a, b, h, d + B);
}
}
}
long long Mn = LLONG_MAX;
for (int h = 0; h <= 4; h ++)
Mn = min(Mn, D[At[k].first][At[k].second][h]);
return !printf("%lld\n", Mn);
}
Compilation message
soccer.cpp: In function 'int main()':
soccer.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
soccer.cpp:13:10: 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:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &k);
~~~~~^~~~~~~~~~
soccer.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &At[i].first, &At[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
12912 KB |
Output is correct |
2 |
Correct |
11 ms |
11384 KB |
Output is correct |
3 |
Correct |
358 ms |
17640 KB |
Output is correct |
4 |
Correct |
359 ms |
17636 KB |
Output is correct |
5 |
Correct |
90 ms |
11384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
436 ms |
17712 KB |
Output is correct |
2 |
Correct |
416 ms |
17660 KB |
Output is correct |
3 |
Correct |
313 ms |
17648 KB |
Output is correct |
4 |
Correct |
290 ms |
17644 KB |
Output is correct |
5 |
Correct |
315 ms |
17656 KB |
Output is correct |
6 |
Correct |
329 ms |
17644 KB |
Output is correct |
7 |
Correct |
417 ms |
17680 KB |
Output is correct |
8 |
Correct |
394 ms |
17680 KB |
Output is correct |
9 |
Correct |
421 ms |
17684 KB |
Output is correct |
10 |
Correct |
69 ms |
12960 KB |
Output is correct |
11 |
Correct |
406 ms |
17732 KB |
Output is correct |
12 |
Correct |
411 ms |
17656 KB |
Output is correct |
13 |
Correct |
244 ms |
17640 KB |
Output is correct |
14 |
Correct |
398 ms |
17808 KB |
Output is correct |
15 |
Correct |
311 ms |
17680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
12912 KB |
Output is correct |
2 |
Correct |
11 ms |
11384 KB |
Output is correct |
3 |
Correct |
358 ms |
17640 KB |
Output is correct |
4 |
Correct |
359 ms |
17636 KB |
Output is correct |
5 |
Correct |
90 ms |
11384 KB |
Output is correct |
6 |
Correct |
436 ms |
17712 KB |
Output is correct |
7 |
Correct |
416 ms |
17660 KB |
Output is correct |
8 |
Correct |
313 ms |
17648 KB |
Output is correct |
9 |
Correct |
290 ms |
17644 KB |
Output is correct |
10 |
Correct |
315 ms |
17656 KB |
Output is correct |
11 |
Correct |
329 ms |
17644 KB |
Output is correct |
12 |
Correct |
417 ms |
17680 KB |
Output is correct |
13 |
Correct |
394 ms |
17680 KB |
Output is correct |
14 |
Correct |
421 ms |
17684 KB |
Output is correct |
15 |
Correct |
69 ms |
12960 KB |
Output is correct |
16 |
Correct |
406 ms |
17732 KB |
Output is correct |
17 |
Correct |
411 ms |
17656 KB |
Output is correct |
18 |
Correct |
244 ms |
17640 KB |
Output is correct |
19 |
Correct |
398 ms |
17808 KB |
Output is correct |
20 |
Correct |
311 ms |
17680 KB |
Output is correct |
21 |
Correct |
100 ms |
11904 KB |
Output is correct |
22 |
Correct |
497 ms |
17672 KB |
Output is correct |
23 |
Correct |
454 ms |
14592 KB |
Output is correct |
24 |
Correct |
514 ms |
14764 KB |
Output is correct |
25 |
Correct |
414 ms |
17660 KB |
Output is correct |
26 |
Correct |
459 ms |
17824 KB |
Output is correct |
27 |
Correct |
300 ms |
12680 KB |
Output is correct |
28 |
Correct |
288 ms |
13144 KB |
Output is correct |
29 |
Correct |
423 ms |
15988 KB |
Output is correct |
30 |
Correct |
254 ms |
13048 KB |
Output is correct |
31 |
Correct |
406 ms |
17680 KB |
Output is correct |
32 |
Correct |
520 ms |
19076 KB |
Output is correct |
33 |
Correct |
347 ms |
17636 KB |
Output is correct |
34 |
Correct |
537 ms |
17812 KB |
Output is correct |
35 |
Correct |
266 ms |
13004 KB |
Output is correct |