Submission #651133

# Submission time Handle Problem Language Result Execution time Memory
651133 2022-10-17T10:25:29 Z lukameladze Soccer (JOI17_soccer) C++14
5 / 100
470 ms 34396 KB
# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 1000, inf = 1e18;
int t,n,a,b,c,h,w,x[N],y[N],dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};
int dp[N][N][10],dist[N][N];
int check(int x, int y) {
    return (!(x <= 0 || y <= 0 || x > h || y > w));
}
void bfs() {
    queue <pii> q;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            dist[i][j] = inf;
        }
    }
    for (int i = 1; i <= n; i++) {
        dist[x[i]][y[i]] = 0;
        q.push({x[i],y[i]});
    }
    while (!q.empty()) {
        int x = q.front().f;
        int y = q.front().s;
        q.pop();
        for (int i = 0; i <= 3; i++) {
            int nx = x + dx[i]; int ny = y + dy[i];
            if (check(nx,ny) && dist[nx][ny] == inf) {
                dist[nx][ny] = dist[x][y] + 1;
                q.push({nx,ny});
            }
        }
    }
}
void dijkstra() {
    priority_queue < pair <pii, pii > > q;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++ ){
            for (int k = 0; k <= 4; k++) {
                dp[i][j][k] = inf;
            }
        }
    }
    q.push({{0,4},{x[1],y[1]}});
    dp[x[1]][y[1]][4] = 0;
    while (!q.empty()) {
        int dis = -q.top().f.f;
        int dir = q.top().f.s;
        int x = q.top().s.f;
        int y = q.top().s.s;
        q.pop();
        if (dp[x][y][dir] < dis) continue;
        
        if (dir == 4) {
            for (int i = 0; i <= 3; i++) {
                int nx = x + dx[i]; int ny = y + dy[i];
                if (dp[x][y][i] > dp[x][y][4] + b) {
                    dp[x][y][i] = dp[x][y][4] + b;
                    q.push({{-dp[x][y][i], i},{x,y}});
                }
                
                if (check(nx,ny) && dp[nx][ny][i] > dp[x][y][dir] + b + c){
                    dp[nx][ny][i] = dp[x][y][dir] + b + c;
                    q.push({{-dp[nx][ny][i], i},{nx,ny}});
                }
            }
            for (int i = 0; i <= 3; i++) {
                int nx = x + dx[i]; int ny = y + dy[i];
                if (check(nx,ny) && dp[nx][ny][4] > dp[x][y][dir] + c) {
                    dp[nx][ny][4] = dp[x][y][4] + c;
                    q.push({{-dp[nx][ny][4], 4},{nx,ny}});
                }
            }
        }
        else {
            if (dp[x][y][4] > dp[x][y][dir] + c*dist[x][y]) {
                dp[x][y][4] = dp[x][y][dir] + c*dist[x][y];
                q.push({{-dp[x][y][4], 4},{x,y}});
            }
            int nx = x + dx[dir];
            int ny = y + dy[dir];
            //if (x == 4 && y == 6 && dir == 2) cout<<nx<<" "<<ny<<"\n";
            if (dp[nx][ny][dir] > dp[x][y][dir] + a) {
                dp[nx][ny][dir] = dp[x][y][dir] + a;
                q.push({{-dp[nx][ny][dir], dir},{nx,ny}});
            }
        }
    }
    int ans = inf;
    for (int i = 0; i <= 4; i++) {
        ans = min(ans,dp[x[n]][y[n]][i]);
    }
    cout<<ans<<"\n";
}
main() {
    std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>h>>w; h++;w++;
    cin>>a>>b>>c;
    cin>>n;
    
    for (int i = 1; i <= n; i++) {
        cin>>x[i]>>y[i];
        x[i]++;
        y[i]++;
    }
    bfs();
    dijkstra();
}

Compilation message

soccer.cpp:98:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   98 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 91 ms 10172 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 387 ms 34244 KB Output is correct
4 Correct 403 ms 34232 KB Output is correct
5 Correct 88 ms 11372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 470 ms 34300 KB Output is correct
2 Correct 439 ms 34396 KB Output is correct
3 Correct 327 ms 29188 KB Output is correct
4 Correct 291 ms 34184 KB Output is correct
5 Correct 338 ms 30128 KB Output is correct
6 Correct 313 ms 34260 KB Output is correct
7 Incorrect 4 ms 5972 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 10172 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 387 ms 34244 KB Output is correct
4 Correct 403 ms 34232 KB Output is correct
5 Correct 88 ms 11372 KB Output is correct
6 Correct 470 ms 34300 KB Output is correct
7 Correct 439 ms 34396 KB Output is correct
8 Correct 327 ms 29188 KB Output is correct
9 Correct 291 ms 34184 KB Output is correct
10 Correct 338 ms 30128 KB Output is correct
11 Correct 313 ms 34260 KB Output is correct
12 Incorrect 4 ms 5972 KB Output isn't correct
13 Halted 0 ms 0 KB -