제출 #239563

#제출 시각아이디문제언어결과실행 시간메모리
239563MrRobot_28Spirale (COCI18_spirale)C++17
80 / 80
41 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); // cout.tie(NULL); int n, m, k; cin >> n >> m >> k; vector <vector <int> > mat(n, vector <int> (m, 1e18)); for(int i = 0; i < k; i++) { int x, y, t; cin >> x >> y >> t; x--; y--; if(t == 0) { for(int s1 = 0; s1 < n; s1++) { for(int s2 = 0; s2 < m; s2++){ if(s1 == x && s2 == y) { mat[s1][s2] = 1; continue; } int e = max(abs(s1 - x) - 1, abs(s2 - y) - 1); int sq = (e * 2 + 1) * (e * 2 + 1); if(x - e - 1 == s1 && s2 >= y - e) { mat[s1][s2] = min(mat[s1][s2], sq + 1 + s2 - (y - e)); } else if(y + e + 1 == s2 && s1 >= x - e - 1) { mat[s1][s2] = min(mat[s1][s2], sq + 2 + 2 * e + s1 - (x - e - 1)); } else if(x + e + 1 == s1 && s2 <= y + e + 1) { mat[s1][s2] = min(mat[s1][s2], sq + 4 * e + 4 + (y + e + 1 - s2)); } else { mat[s1][s2] = min(mat[s1][s2], sq + 6 * e + 6 + (x + 1 + e - s1)); } } } } else { for(int s1 = 0; s1 < n; s1++) { for(int s2 = 0; s2 < m; s2++) { if(s1 == x && s2 == y) { mat[s1][s2] = 1; continue; } int e = max(abs(s1 - x), abs(s2 - y)) - 1; int sq = (2 * e + 1) * (2 * e + 1); if(s1 == x + e + 1 && s2 <= y + e + 1) { mat[s1][s2] = min(mat[s1][s2], sq + 4 * e + 4 + (s2 - (y - e - 1))); } else if(s2 == y - e - 1 && s1 <= x + e + 1) { mat[s1][s2] = min(mat[s1][s2], sq + 2 * e + 2 + (s1 - (x - e - 1))); } else if(s1 == x - e - 1 && s2 <= y + e) { mat[s1][s2] = min(mat[s1][s2], sq + 1 + (y + e - s2)); } else { mat[s1][s2] = min(mat[s1][s2], sq + 6 * e + 6 + (x + e + 1 - s1)); } } } } } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cout << mat[i][j] << " "; } cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...