# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1026088 | 2024-07-17T14:19:41 Z | phong | Soccer (JOI17_soccer) | C++17 | 622 ms | 55848 KB |
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define ll long long //#define int long long const int nmax = 500 + 5; const int lg = 18; const int base = 311; const int M = 5e6; const ll oo = 1e18 + 1; const int mod = 987654321; #define fi first #define se second #define endl "\n" #define debug(a, m) for(int j = 1; j <= n; ++j) cout << a[j] << ' ';cout << endl; #define pii pair<ll, int> using namespace std; int n, m, q, vis[nmax][nmax]; ll A, B, C; ll dp[nmax][nmax][3][4]; ll F[nmax][nmax]; struct node{ ll w; int x, y, id, h; friend bool operator < (const node&a, const node&b){ return a.w > b.w; } }; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; pii a[nmax * nmax]; main(){ ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); // freopen("code.inp", "r", stdin); // freopen("code.out", "w", stdout); cin >> n >> m; cin >> A >> B >> C; cin >> q; for(int i = 1, u, v; i <= q; ++i){ cin >> u >> v; a[i]= {u, v}; vis[u][v] = 1; } memset(dp, 0x3f, sizeof dp); memset(F, 0x3f, sizeof F); priority_queue<node> two; for(int i = 0; i <= n; ++i){ for(int j = 0; j <= m; ++j){ if(vis[i][j]){ F[i][j] = 0; two.push({F[i][j], i, j}); } } } while(two.size()){ node tmp = two.top();two.pop(); if(tmp.w != F[tmp.x][tmp.y]) continue; for(int k = 0; k < 4; ++k){ int i = dx[k] + tmp.x; int j = dy[k] + tmp.y; if(i >= 0 && i <= n && j >= 0 && j <= m){ if(F[i][j] > tmp.w + C){ F[i][j] = tmp.w + C; two.push({tmp.w + C, i, j}); } } } } priority_queue<node> one; for(int j = 0; j < 4; ++j){ dp[a[1].fi][a[1].se][0][j] = 0; one.push({0, a[1].fi, a[1].se, 0, j}); } while(one.size()){ node tmp = one.top();one.pop(); if(tmp.w != dp[tmp.x][tmp.y][tmp.id][tmp.h]) continue; if(tmp.id == 0){ int i = dx[tmp.h] + tmp.x; int j = dy[tmp.h] + tmp.y; if(i >= 0 && i <= n && j >= 0 && j <= m){ if(dp[i][j][0][tmp.h] > tmp.w + C){ dp[i][j][0][tmp.h] = tmp.w + C; one.push({tmp.w + C, i, j, 0, tmp.h}); } } if(dp[tmp.x][tmp.y][tmp.id + 1][tmp.h] > tmp.w){ dp[tmp.x][tmp.y][tmp.id + 1][tmp.h] = tmp.w; one.push({tmp.w, tmp.x, tmp.y, tmp.id + 1, tmp.h}); } for(int k =0; k < 4; ++k){ if(dp[tmp.x][tmp.y][0][k] > tmp.w){ dp[tmp.x][tmp.y][0][k] = tmp.w; one.push({tmp.w, tmp.x, tmp.y, tmp.id, k}); } } } else{ if(tmp.id == 1){ int i = dx[tmp.h] + tmp.x; int j = dy[tmp.h] + tmp.y; if(i >= 0 && i <= n && j >= 0 && j <= m){ if(dp[i][j][1][tmp.h] > tmp.w + A){ dp[i][j][1][tmp.h] = tmp.w + A; one.push({tmp.w + A, i, j, 1, tmp.h}); } } if(dp[tmp.x][tmp.y][tmp.id ^ 1][tmp.h] > tmp.w + B + F[tmp.x][tmp.y]){ dp[tmp.x][tmp.y][tmp.id ^ 1][tmp.h] = tmp.w + B + F[tmp.x][tmp.y]; one.push({tmp.w + F[tmp.x][tmp.y] + B, tmp.x, tmp.y, tmp.id ^ 1, tmp.h}); } } } } ll ans = oo; // cout << dp[1][5][0][1] << ' ' << F[1][4]; for(int i = 0; i < 4; ++i){ ans = min({ans, dp[a[q].fi][a[q].se][0][i]}); } cout << ans; } /* 4 4 1 12 6 11 11 10 2 14 10 1 9 20 4 17 19 10 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 30536 KB | Output is correct |
2 | Correct | 5 ms | 27228 KB | Output is correct |
3 | Correct | 363 ms | 33608 KB | Output is correct |
4 | Correct | 429 ms | 39916 KB | Output is correct |
5 | Correct | 69 ms | 27500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 532 ms | 52140 KB | Output is correct |
2 | Correct | 479 ms | 52068 KB | Output is correct |
3 | Correct | 353 ms | 39920 KB | Output is correct |
4 | Correct | 347 ms | 33776 KB | Output is correct |
5 | Correct | 360 ms | 39800 KB | Output is correct |
6 | Correct | 366 ms | 39908 KB | Output is correct |
7 | Correct | 501 ms | 52516 KB | Output is correct |
8 | Correct | 435 ms | 52308 KB | Output is correct |
9 | Correct | 480 ms | 52520 KB | Output is correct |
10 | Correct | 65 ms | 33924 KB | Output is correct |
11 | Correct | 499 ms | 52520 KB | Output is correct |
12 | Correct | 491 ms | 52328 KB | Output is correct |
13 | Correct | 278 ms | 39908 KB | Output is correct |
14 | Correct | 503 ms | 52524 KB | Output is correct |
15 | Correct | 388 ms | 52392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 30536 KB | Output is correct |
2 | Correct | 5 ms | 27228 KB | Output is correct |
3 | Correct | 363 ms | 33608 KB | Output is correct |
4 | Correct | 429 ms | 39916 KB | Output is correct |
5 | Correct | 69 ms | 27500 KB | Output is correct |
6 | Correct | 532 ms | 52140 KB | Output is correct |
7 | Correct | 479 ms | 52068 KB | Output is correct |
8 | Correct | 353 ms | 39920 KB | Output is correct |
9 | Correct | 347 ms | 33776 KB | Output is correct |
10 | Correct | 360 ms | 39800 KB | Output is correct |
11 | Correct | 366 ms | 39908 KB | Output is correct |
12 | Correct | 501 ms | 52516 KB | Output is correct |
13 | Correct | 435 ms | 52308 KB | Output is correct |
14 | Correct | 480 ms | 52520 KB | Output is correct |
15 | Correct | 65 ms | 33924 KB | Output is correct |
16 | Correct | 499 ms | 52520 KB | Output is correct |
17 | Correct | 491 ms | 52328 KB | Output is correct |
18 | Correct | 278 ms | 39908 KB | Output is correct |
19 | Correct | 503 ms | 52524 KB | Output is correct |
20 | Correct | 388 ms | 52392 KB | Output is correct |
21 | Correct | 105 ms | 27988 KB | Output is correct |
22 | Correct | 543 ms | 39956 KB | Output is correct |
23 | Correct | 519 ms | 39904 KB | Output is correct |
24 | Correct | 592 ms | 40252 KB | Output is correct |
25 | Correct | 440 ms | 39908 KB | Output is correct |
26 | Correct | 471 ms | 34368 KB | Output is correct |
27 | Correct | 253 ms | 33232 KB | Output is correct |
28 | Correct | 314 ms | 36496 KB | Output is correct |
29 | Correct | 399 ms | 34628 KB | Output is correct |
30 | Correct | 236 ms | 33488 KB | Output is correct |
31 | Correct | 563 ms | 52520 KB | Output is correct |
32 | Correct | 622 ms | 55848 KB | Output is correct |
33 | Correct | 391 ms | 39908 KB | Output is correct |
34 | Correct | 602 ms | 52768 KB | Output is correct |
35 | Correct | 192 ms | 31948 KB | Output is correct |