Submission #685409

# Submission time Handle Problem Language Result Execution time Memory
685409 2023-01-24T10:14:52 Z coffee5427 Soccer (JOI17_soccer) C++17
0 / 100
315 ms 62444 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define ALL(x) x.begin(), x.end()

using namespace std;
using PQ = priority_queue<int, vector<int>, greater<int>>;
 
const int INF = 2e18;
const int maxn = 500 + 5;
const int maxm = 1e6 + 5;
const int M = 1e9 + 7;

int n, m, t;
int A, B, C;
int dis[maxm], dt[maxn][maxn];
int sum, cnt;
int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
queue<pii> q;
vector<pii> G[maxm];
vector<pii> pt;

void build () {
    while (q.size ()) {
        auto [i, j] = q.front ();
        q.pop ();

        for (auto [u, v] : d) {
            int ni = i + u, nj = j + v;
            if (ni > n || ni < 0 || nj > m || nj < 0) continue;
            if (dt[ni][nj] < INF) continue;
            
            dt[ni][nj] = dt[i][j] + 1;
            q.push ({ni, nj});
        }
    }
}

string de (int p) {
    int j = p % (m + 1);
    int i = (p - j) / (m + 1);
   
    cout << "(" << i << "," << j << ")";
    return "";
}

string print (int u) {
    int k = u / sum;
    int p = u - k * sum;

    cout << "p:" << de (p) << ",k:" << k;
    return "";
}

void add_edge (int u, int v, int w) {
    //cout << "u:" << u << ",v:" << v << ",w:" << w << "\n";
    // cnt++;
    // if (cnt > 20) exit(0);
    G[u].pb ({v, w});
}

int id (int i, int j) {
    return i * (m + 1) + j;
}

void dijkstra () {
    memset (dis, 0x3f, sizeof dis);
    priority_queue <pii, vector<pii>, greater<>> pq;
    
    int pos = id (pt[1].F, pt[1].S);
    pq.push ({0, pos + 4 * sum});

    while (pq.size ()) {
        auto [W, u] = pq.top ();
        //
        pq.pop ();
        
        if (dis[u] < INF) continue;
        dis[u] = W;
        //cout << "u:" << print (u) << ",w:" << W << "\n";
        //cout << "sz:" << G[u].size () << "\n";

        for (auto [v, w] : G[u]) {
            //cout << "v:" << print (v);
            pq.push ({W + w, v});
        }
    }
}

void init () {
    memset (dt, 0x3f, sizeof dt);
    cin >> n >> m;
    cin >> A >> B >> C;
    cin >> t;
    sum = (n + 1) * (m + 1);
    pt.resize (t + 1);

    for (int i = 1; i <= t; i++) {
        int &x = pt[i].F, &y = pt[i].S;
        cin >> x >> y;
        q.push ({x, y});
        dt[x][y] = 0;
    }
}

void solve () {
    build ();

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            int p = id (i, j);
            // cout << "i:" << i << ",j:" << j << "\n";
            // cout << "id:" << de (p) << "\n";
            for (int k = 0; k < 4; k++) {
                //cout << "p:" << p << ",k:" << k << ",sum:" << sum << "\n";
                add_edge (p + k * sum, p + 4  * sum, 0);
                add_edge (p + 5 * sum, p + k * sum, B);
                add_edge (p + 4 * sum, p + 5 * sum, dt[i][j] * C);

                int ni = i + d[k][0], nj = j + d[k][1];
        //         cout << "k:" << k << "\n";
        //         cout << "p:" "(" << i << "," << j << ")" << "\n";
        // cout << "q:" << "(" << ni << "," << nj << ")" << "\n";
                if (ni > n || ni < 0 || nj > m || nj < 0) continue;
                int q = id (ni, nj);
                // cout << "p:" << de (p) << "\n";
                // cout << "q:" << de (q) << "\n";
                add_edge (p + k * sum, q + k * sum, A);
                add_edge (p + 5 * sum, q + 5 * sum, C);
            }
        }
    }
    dijkstra ();
    int ans = INF;
    for (int i = 0; i < 6; i++) {
        ans = min (ans, dis [id (pt[t].F, pt[t].S) + i * sum]);
    }

    cout << ans << "\n";
} 
 
signed main() {
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        init();
        solve();
    }
} 
# Verdict Execution time Memory Grader output
1 Correct 315 ms 62444 KB Output is correct
2 Correct 18 ms 33624 KB Output is correct
3 Runtime error 39 ms 52032 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 38 ms 52176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 315 ms 62444 KB Output is correct
2 Correct 18 ms 33624 KB Output is correct
3 Runtime error 39 ms 52032 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -