제출 #758358

#제출 시각아이디문제언어결과실행 시간메모리
7583581binSoccer (JOI17_soccer)C++14
100 / 100
770 ms49780 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 505;
ll h, w, a, b, c, n, x, y, P[NMAX][NMAX], dist[5][NMAX][NMAX];
vector<pair<ll, ll>> v;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> h >> w >> a >> b >> c >> n;
    queue<pair<int, int>> q;
    memset(P, -1, sizeof(P));
    for(int i = 0; i < n; i++) {
        cin >> y >> x;
        q.emplace(x, y); P[x][y] = 0;
        v.emplace_back(x, y);
    }
    while(q.size()){
        auto&[x, y] = q.front(); q.pop();
        for(int k = 0; k < 4; k++){
            int ny = y + dy[k];
            int nx = x + dx[k];
            if(ny < 0 || nx < 0 || ny > h || nx > w || P[nx][ny] != -1) continue;
            P[nx][ny] = P[x][y] + c;
            q.emplace(nx, ny);
        }
    }
    
    memset(dist, 0x3f, sizeof(dist));
    priority_queue<tuple<ll, ll, ll, ll>> pq;
    pq.emplace(0, 4, v[0].first, v[0].second);
    dist[4][v[0].first][v[0].second] = 0;
    
    while(pq.size()){
        auto[d, t, x, y] = pq.top(); pq.pop();
        d = -d;
        if(d > dist[t][x][y]) continue;
        
        if(t < 4){
            if(d < dist[4][x][y]){
                dist[4][x][y] = d;
                pq.emplace(-d, 4, x, y);    
            }
            int ny = y + dy[t];
            int nx = x + dx[t];
            if(ny < 0 || nx < 0 || ny > h || nx > w) continue;
            if(d + a < dist[t][nx][ny]){
                dist[t][nx][ny] = d + a;
                pq.emplace(-d-a, t, nx, ny);
            }
        }
        else{
            for(int k = 0; k < 4; k++){
               int ny = y + dy[k];
                int nx = x + dx[k];
                if(ny < 0 || nx < 0 || ny > h || nx > w) continue;
                if(d + c < dist[4][nx][ny]){
                    dist[4][nx][ny] = d + c;
                    pq.emplace(-d-c, 4, nx, ny);
                }
                if(d + a + b + P[x][y] < dist[k][nx][ny]){
                    dist[k][nx][ny] = d + a + b + P[x][y];
                    pq.emplace(-d-a-b-P[x][y], k, nx, ny);
                }
            }
        }   
    }
    cout << dist[4][v[n - 1].first][v[n - 1].second];
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

soccer.cpp: In function 'int main()':
soccer.cpp:25:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |         auto&[x, y] = q.front(); q.pop();
      |              ^
soccer.cpp:41:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |         auto[d, t, x, y] = pq.top(); pq.pop();
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...