#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n, m, k, ans[N][N], mat[N][N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// U R D L
vector<int> vec;
bool valid(int x, int y){
return (x > 0 and y > 0 and x <= n and y <= m);
}
void work(int x, int y, int t){
int cur = 1;
for (int i = 0; i < vec.size(); i ++){
int d = i % 4;
if (t) d *= -1;
d = (d + 4) % 4;
for (int j = 0; j < vec[i]; j ++){
x += dx[d];
y += dy[d];
cur++;
if (valid(x, y)){
mat[x][y] = cur;
ans[x][y] = min(ans[x][y], mat[x][y]);
}
}
}
}
int main(){
memset(ans, 31, sizeof ans);
for (int i = 1; i <= 100; i ++)
vec.push_back(i), vec.push_back(i);
cin >> n >> m >> k;
for (int i = 0; i < k; i ++){
int x, y, t;
cin >> x >> y >> t;
memset(mat, 31, sizeof mat);
ans[x][y] = mat[x][y] = 1;
work(x, y, t);
}
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= m; j ++)
cout << ans[i][j] << " ";
cout << endl;
}
}
Compilation message
spirale.cpp: In function 'void work(int, int, int)':
spirale.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < vec.size(); i ++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
78 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |