# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
251951 | Vladikus004 | Spirale (COCI18_spirale) | C++14 | 171 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |