Submission #251950

#TimeUsernameProblemLanguageResultExecution timeMemory
251950Vladikus004Spirale (COCI18_spirale)C++14
72 / 80
1 ms384 KiB
#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 = 51; int n, m, k, x[N], y[N], t[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 timeMemoryGrader output
Fetching results...