답안 #192843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
192843 2020-01-15T07:23:13 Z Akashi Soccer (JOI17_soccer) C++14
100 / 100
1162 ms 38556 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};

struct state{
    long long cost;
    int x, y, dir;

    bool operator < (const state &aux)const{
        return cost > aux.cost;
    }
};

int n, m, k, a, b, c;
int x[100005], y[100005];

long long ad[6];
long long d[505][505][6];

priority_queue <state> pq;

inline void Move(int l, int c, long long cost, int dir){
    for(int k = 0; k < 4 ; ++k){
        int x = l + dx[k];
        int y = c + dy[k];
        if(!(x > 0 && y > 0 && x <= n && y <= m)) continue ;

        if(cost + ad[dir] < d[x][y][dir]){
            d[x][y][dir] = cost + ad[dir];
            pq.push({d[x][y][dir], x, y, dir});
        }
    }
}

inline void Throw(int l, int c, long long cost, int dir){
    int x = l + dx[dir], y = c + dy[dir];
    if(x > 0 && y > 0 && x <= n && y <= m && d[x][y][dir] > cost + ad[dir]){
        d[x][y][dir] = cost + ad[dir];
        pq.push({d[x][y][dir], x, y, dir});
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d", &k);

    for(int k = 0; k < 4 ; ++k) ad[k] = a;
    ad[4] = ad[5] = c;

    ++n; ++m;
    for(int i = 1; i <= k ; ++i){
        scanf("%d%d", &x[i], &y[i]);
        ++x[i]; ++y[i];
    }

    for(int i = 1; i <= n ; ++i)
        for(int j = 1; j <= m ; ++j)
            for(int k = 0; k < 6 ; ++k) d[i][j][k] = INF;

    for(int i = 1; i <= k ; ++i){
        d[x[i]][y[i]][5] = 0;
        pq.push({0, x[i], y[i], 5});
    }

    d[x[1]][y[1]][4] = 0;
    pq.push({0, x[1], y[1], 4});

    while(!pq.empty()){
        int l = pq.top().x, c = pq.top().y, dir = pq.top().dir;
        pq.pop();

        if(dir == 4){
            Move(l, c, d[l][c][4], 4);
            for(int k = 0; k < 4 ; ++k) Throw(l, c, d[l][c][4] + b, k);
        }

        if(dir < 4){
            Throw(l, c, d[l][c][dir], dir);
        }

        if(dir == 5){
            Move(l, c, d[l][c][5], 5);
        }

        long long Min = INF;
        for(int k = 0; k < 4 ; ++k) Min = min(Min, d[l][c][k]);
        if((dir == 5 || dir < 4) && (d[l][c][5] != INF && Min != INF)){
            Move(l, c, d[l][c][5] + Min, 4);
            for(int k = 0; k < 4 ; ++k) Throw(l, c, d[l][c][5] + Min + b, k);
        }
    }

    long long Sol = INF;
    for(int dir = 0; dir <= 4 ; ++dir) Sol = min(Sol, d[x[k]][y[k]][dir]);

    printf("%lld", Sol);
    return 0;
}























Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:48: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:49: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:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &k);
     ~~~~~^~~~~~~~~~
soccer.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x[i], &y[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 7656 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 637 ms 18580 KB Output is correct
4 Correct 618 ms 18728 KB Output is correct
5 Correct 141 ms 7780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 687 ms 24780 KB Output is correct
2 Correct 584 ms 18688 KB Output is correct
3 Correct 477 ms 16300 KB Output is correct
4 Correct 592 ms 24636 KB Output is correct
5 Correct 476 ms 18016 KB Output is correct
6 Correct 484 ms 18536 KB Output is correct
7 Correct 442 ms 15464 KB Output is correct
8 Correct 437 ms 15468 KB Output is correct
9 Correct 738 ms 37024 KB Output is correct
10 Correct 121 ms 10592 KB Output is correct
11 Correct 502 ms 15464 KB Output is correct
12 Correct 583 ms 18528 KB Output is correct
13 Correct 362 ms 16100 KB Output is correct
14 Correct 500 ms 18512 KB Output is correct
15 Correct 402 ms 18020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 7656 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 637 ms 18580 KB Output is correct
4 Correct 618 ms 18728 KB Output is correct
5 Correct 141 ms 7780 KB Output is correct
6 Correct 687 ms 24780 KB Output is correct
7 Correct 584 ms 18688 KB Output is correct
8 Correct 477 ms 16300 KB Output is correct
9 Correct 592 ms 24636 KB Output is correct
10 Correct 476 ms 18016 KB Output is correct
11 Correct 484 ms 18536 KB Output is correct
12 Correct 442 ms 15464 KB Output is correct
13 Correct 437 ms 15468 KB Output is correct
14 Correct 738 ms 37024 KB Output is correct
15 Correct 121 ms 10592 KB Output is correct
16 Correct 502 ms 15464 KB Output is correct
17 Correct 583 ms 18528 KB Output is correct
18 Correct 362 ms 16100 KB Output is correct
19 Correct 500 ms 18512 KB Output is correct
20 Correct 402 ms 18020 KB Output is correct
21 Correct 112 ms 6956 KB Output is correct
22 Correct 941 ms 24712 KB Output is correct
23 Correct 1162 ms 23552 KB Output is correct
24 Correct 1145 ms 24664 KB Output is correct
25 Correct 804 ms 18568 KB Output is correct
26 Correct 816 ms 18572 KB Output is correct
27 Correct 298 ms 16528 KB Output is correct
28 Correct 492 ms 20040 KB Output is correct
29 Correct 796 ms 26140 KB Output is correct
30 Correct 634 ms 17000 KB Output is correct
31 Correct 565 ms 18568 KB Output is correct
32 Correct 1002 ms 38556 KB Output is correct
33 Correct 782 ms 18512 KB Output is correct
34 Correct 1075 ms 37036 KB Output is correct
35 Correct 291 ms 16972 KB Output is correct