# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1090190 |
2024-09-17T23:35:51 Z |
ShaShi |
Portals (BOI14_portals) |
C++17 |
|
504 ms |
158800 KB |
#include <bits/stdc++.h>
// #define int long long
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define endl "\n"
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;
const int MAXN = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, flag2;
int arr[MAXN][MAXN], dis[MAXN][MAXN], dp[4][MAXN][MAXN]; pii start, final;
vector<pair<pii, int>> adj[MAXN][MAXN]; char ch;
priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq;
inline void add_edge(pii x, pii y, int w=1) { adj[x.F][x.S].pb({y, w}); }
int32_t main() {
#ifdef LOCAL
freopen("inp.in", "r", stdin);
freopen("res.out", "w", stdout);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
cin >> n >> m;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin >> ch;
if (ch == 'C') final = {i, j}, arr[i][j] = 1;
else if (ch == 'S') start = {i, j}, arr[i][j] = 1;
else if (ch == '.') arr[i][j] = 1;
add_edge({i, j}, {i+1, j}); add_edge({i, j}, {i-1, j});
add_edge({i, j}, {i, j+1}); add_edge({i, j}, {i, j-1});
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
if (!arr[i][j]) dp[0][i][j] = 0;
else dp[0][i][j] = dp[0][i-1][j]+1;
if (!arr[i][j]) dp[3][i][j] = 0;
else dp[3][i][j] = dp[3][i][j-1]+1;
}
}
for (int i=n; i>=1; i--) {
for (int j=m; j>=1; j--) {
if (!arr[i][j]) dp[1][i][j] = 0;
else dp[1][i][j] = dp[1][i][j+1]+1;
if (!arr[i][j]) dp[2][i][j] = 0;
else dp[2][i][j] = dp[2][i+1][j]+1;
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
if (!arr[i][j]) continue;
tmp = min({dp[0][i][j], dp[1][i][j], dp[2][i][j], dp[3][i][j]});
add_edge({i, j}, {i-dp[0][i][j]+1, j}, tmp);
add_edge({i, j}, {i+dp[2][i][j]-1, j}, tmp);
add_edge({i, j}, {i, j-dp[3][i][j]+1}, tmp);
add_edge({i, j}, {i, j+dp[1][i][j]-1}, tmp);
}
}
memset(dis, 1, sizeof(dis));
dis[start.F][start.S] = 0; pq.push({0, start});
while (pq.size()) {
auto cur = pq.top(); pq.pop();
if (dis[cur.S.F][cur.S.S] != cur.F) continue;
pii u = cur.S;
if (u == final) kill(cur.F);
for (auto cur:adj[u.F][u.S]) {
if (arr[cur.F.F][cur.F.S] && dis[cur.F.F][cur.F.S] > dis[u.F][u.S]+cur.S) {
dis[cur.F.F][cur.F.S] = dis[u.F][u.S]+cur.S;
pq.push({dis[cur.F.F][cur.F.S], cur.F});
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
28252 KB |
Output is correct |
2 |
Correct |
12 ms |
28252 KB |
Output is correct |
3 |
Correct |
12 ms |
28252 KB |
Output is correct |
4 |
Correct |
13 ms |
28252 KB |
Output is correct |
5 |
Correct |
15 ms |
28248 KB |
Output is correct |
6 |
Correct |
12 ms |
28252 KB |
Output is correct |
7 |
Correct |
12 ms |
28464 KB |
Output is correct |
8 |
Correct |
13 ms |
28252 KB |
Output is correct |
9 |
Correct |
12 ms |
28248 KB |
Output is correct |
10 |
Correct |
12 ms |
28252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
28252 KB |
Output is correct |
2 |
Correct |
13 ms |
28220 KB |
Output is correct |
3 |
Correct |
13 ms |
28252 KB |
Output is correct |
4 |
Correct |
13 ms |
28252 KB |
Output is correct |
5 |
Correct |
14 ms |
28252 KB |
Output is correct |
6 |
Correct |
13 ms |
28252 KB |
Output is correct |
7 |
Correct |
13 ms |
28420 KB |
Output is correct |
8 |
Correct |
13 ms |
28252 KB |
Output is correct |
9 |
Correct |
14 ms |
29448 KB |
Output is correct |
10 |
Correct |
13 ms |
29532 KB |
Output is correct |
11 |
Correct |
13 ms |
29532 KB |
Output is correct |
12 |
Correct |
13 ms |
29548 KB |
Output is correct |
13 |
Correct |
14 ms |
29528 KB |
Output is correct |
14 |
Correct |
14 ms |
28380 KB |
Output is correct |
15 |
Correct |
14 ms |
29272 KB |
Output is correct |
16 |
Correct |
13 ms |
28252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
28120 KB |
Output is correct |
2 |
Correct |
13 ms |
28312 KB |
Output is correct |
3 |
Correct |
13 ms |
28252 KB |
Output is correct |
4 |
Correct |
13 ms |
28364 KB |
Output is correct |
5 |
Correct |
24 ms |
36440 KB |
Output is correct |
6 |
Correct |
25 ms |
36444 KB |
Output is correct |
7 |
Correct |
23 ms |
36276 KB |
Output is correct |
8 |
Correct |
22 ms |
36072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
28248 KB |
Output is correct |
2 |
Correct |
19 ms |
28256 KB |
Output is correct |
3 |
Correct |
13 ms |
28252 KB |
Output is correct |
4 |
Correct |
14 ms |
28252 KB |
Output is correct |
5 |
Correct |
12 ms |
28256 KB |
Output is correct |
6 |
Correct |
12 ms |
28252 KB |
Output is correct |
7 |
Correct |
12 ms |
28256 KB |
Output is correct |
8 |
Correct |
12 ms |
28408 KB |
Output is correct |
9 |
Correct |
13 ms |
29460 KB |
Output is correct |
10 |
Correct |
14 ms |
29532 KB |
Output is correct |
11 |
Correct |
13 ms |
29304 KB |
Output is correct |
12 |
Correct |
14 ms |
29532 KB |
Output is correct |
13 |
Correct |
13 ms |
29532 KB |
Output is correct |
14 |
Correct |
23 ms |
36188 KB |
Output is correct |
15 |
Correct |
28 ms |
36404 KB |
Output is correct |
16 |
Correct |
26 ms |
36444 KB |
Output is correct |
17 |
Correct |
25 ms |
36188 KB |
Output is correct |
18 |
Correct |
26 ms |
36444 KB |
Output is correct |
19 |
Correct |
20 ms |
36652 KB |
Output is correct |
20 |
Correct |
25 ms |
36708 KB |
Output is correct |
21 |
Correct |
24 ms |
36412 KB |
Output is correct |
22 |
Correct |
23 ms |
36444 KB |
Output is correct |
23 |
Correct |
25 ms |
36444 KB |
Output is correct |
24 |
Correct |
25 ms |
36696 KB |
Output is correct |
25 |
Correct |
12 ms |
28252 KB |
Output is correct |
26 |
Correct |
13 ms |
29412 KB |
Output is correct |
27 |
Correct |
14 ms |
28116 KB |
Output is correct |
28 |
Correct |
24 ms |
36188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
28252 KB |
Output is correct |
2 |
Correct |
13 ms |
28396 KB |
Output is correct |
3 |
Correct |
11 ms |
28252 KB |
Output is correct |
4 |
Correct |
13 ms |
28256 KB |
Output is correct |
5 |
Correct |
12 ms |
28392 KB |
Output is correct |
6 |
Correct |
11 ms |
28252 KB |
Output is correct |
7 |
Correct |
13 ms |
28248 KB |
Output is correct |
8 |
Correct |
15 ms |
28252 KB |
Output is correct |
9 |
Correct |
14 ms |
29532 KB |
Output is correct |
10 |
Correct |
13 ms |
29532 KB |
Output is correct |
11 |
Correct |
12 ms |
29552 KB |
Output is correct |
12 |
Correct |
12 ms |
29528 KB |
Output is correct |
13 |
Correct |
12 ms |
29532 KB |
Output is correct |
14 |
Correct |
21 ms |
36408 KB |
Output is correct |
15 |
Correct |
22 ms |
36444 KB |
Output is correct |
16 |
Correct |
21 ms |
36444 KB |
Output is correct |
17 |
Correct |
21 ms |
36188 KB |
Output is correct |
18 |
Correct |
23 ms |
36444 KB |
Output is correct |
19 |
Correct |
20 ms |
36696 KB |
Output is correct |
20 |
Correct |
22 ms |
36700 KB |
Output is correct |
21 |
Correct |
21 ms |
36444 KB |
Output is correct |
22 |
Correct |
24 ms |
36444 KB |
Output is correct |
23 |
Correct |
23 ms |
36304 KB |
Output is correct |
24 |
Correct |
324 ms |
152864 KB |
Output is correct |
25 |
Correct |
423 ms |
158800 KB |
Output is correct |
26 |
Correct |
211 ms |
158548 KB |
Output is correct |
27 |
Correct |
340 ms |
158544 KB |
Output is correct |
28 |
Correct |
304 ms |
152400 KB |
Output is correct |
29 |
Correct |
342 ms |
153540 KB |
Output is correct |
30 |
Correct |
318 ms |
153876 KB |
Output is correct |
31 |
Correct |
29 ms |
36700 KB |
Output is correct |
32 |
Correct |
504 ms |
158580 KB |
Output is correct |
33 |
Correct |
13 ms |
28384 KB |
Output is correct |
34 |
Correct |
13 ms |
29276 KB |
Output is correct |
35 |
Correct |
315 ms |
146772 KB |
Output is correct |
36 |
Correct |
12 ms |
28248 KB |
Output is correct |
37 |
Correct |
21 ms |
36072 KB |
Output is correct |
38 |
Correct |
232 ms |
148192 KB |
Output is correct |
39 |
Correct |
240 ms |
134996 KB |
Output is correct |