#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 52;
int n, m, k, x[N * N], y[N * N], t[N * N], d[N][N];
int get_dist(int X, int Y, int ind){
if (X == x[ind] && Y == y[ind]) return 1;
if (t[ind] == 0){
if (abs(X - x[ind]) <= y[ind] - Y){
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (ny != Y){
nx--; ny--;
now += add + 6;
add += 8;
}
while (nx != X){
nx++;
now--;
}
return now;
}else
if (abs(Y - y[ind]) <= X - x[ind]){
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (nx != X){
nx++; ny--;
now += add + 4;
add += 8;
}
while (ny != Y){
ny++;
now--;
}
return now;
}else
if (abs(X - x[ind]) <= -(y[ind] - Y)){
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (ny != Y){
nx++; ny++;
now += add + 2;
add += 8;
}
while (nx != X){
nx--;
now--;
}
return now;
}else{
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (nx != X){
nx--; ny++;
now += add;
add += 8;
}
while (ny != Y){
ny--;
now--;
}
return now;
}
}else{
if (abs(X - x[ind]) <= y[ind] - Y){
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (ny != Y){
nx++; ny--;
now += add + 2;
add += 8;
}
while (nx != X){
nx--;
now--;
}
return now;
}else
if (abs(Y - y[ind]) <= X - x[ind]){
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (nx != X){
nx++; ny++;
now += add + 4;
add += 8;
}
while (ny != Y){
ny--;
now--;
}
return now;
}else
if (abs(X - x[ind]) <= -(y[ind] - Y)){
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (ny != Y){
nx--; ny++;
now += add + 6;
add += 8;
}
while (nx != X){
nx++;
now--;
}
return now;
}else{
int nx = x[ind], ny = y[ind], add = 2, now = 1;
while (nx != X){
nx--; ny--;
now += add;
add += 8;
}
while (ny != Y){
ny++;
now--;
}
return now;
}
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n >> m >> k;
for (int i = 0; i < k; i++){
cin >> x[i] >> y[i] >> t[i];
x[i]--; y[i]--;
}
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
int mn = inf;
for (int g = 0; g < k; g++){
mn = min(mn, get_dist(i, j, g));
}
d[i][j] = mn;
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cout << d[i][j] << " ";
}
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
171 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |