#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int n, m, k;
int adj[1010][1010];
int d[1010*1010];
int get_idx(int i, int j) {
if(i == 0 || i == n+1 || j == 0 || j == m+1) return 0;
return (i - 1) * m + j;
}
int main(void) {
ios_base::sync_with_stdio(0); cin.tie(0);
memset(adj, 0x3f, sizeof(adj));
cin >> n >> m >> k;
for(int i = 1; i <= n+1; ++i) {
for(int j = 1; j <= m; ++j) {
int now; cin >> now;
now = ~now ? now : 1e9 + 7;
int i1 = get_idx(i - 1, j), i2 = get_idx(i, j);
adj[i1][i2] = adj[i2][i1] = min(adj[i1][i2], now);
printf("%d %d %d\n", i1, i2, adj[i1][i2]);
}
}
puts("");
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m+1; ++j) {
int now; cin >> now;
now = ~now ? now : 1e9 + 7;
int i1 = get_idx(i, j - 1), i2 = get_idx(i, j);
adj[i1][i2] = adj[i2][i1] = min(adj[i1][i2], now);
printf("%d %d %d\n", i1, i2, adj[i1][i2]);
}
}
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) d[get_idx(i, j)] = k;
priority_queue<pair<int, int>> pq;
d[0] = 0;
for(int i = 1; i <= n; ++i) {
int nx = i, ny = 1;
int ni = get_idx(nx, ny);
int nw = adj[0][ni];
if(nw < d[ni]) {
d[ni] = nw;
pq.push({-d[ni], ni});
}
ny = m;
ni = get_idx(nx, ny);
nw = adj[0][ni];
if(nw < d[ni]) {
d[ni] = nw;
pq.push({-d[ni], ni});
}
}
for(int i = 1; i <= m; ++i) {
int nx = 1, ny = i;
int ni = get_idx(nx, ny);
int nw = adj[0][ni];
if(nw < d[ni]) {
d[ni] = nw;
pq.push({-d[ni], ni});
}
nx = n;
ni = get_idx(nx, ny);
nw = adj[0][ni];
if(nw < d[ni]) {
d[ni] = nw;
pq.push({-d[ni], ni});
}
}
while(!pq.empty()) {
int wei = -pq.top().first, now = pq.top().second;
pq.pop();
if(wei > d[now]) continue;
printf("%d %d\n", now, wei);
int x = (now - 1) / m + 1, y = (now - 1) % m + 1;
for(int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
int ni = get_idx(nx, ny);
int nw = adj[now][ni];
if(max(wei, nw) < d[ni]) {
d[ni] = max(wei, nw);
pq.push({-d[ni], ni});
}
}
}
int ans = 0;
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) ans += d[get_idx(i, j)];
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
12 ms |
8568 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
15 ms |
8704 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
8696 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |