/*input
4 3 2
1 1 0
1 2 0
*/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 111 * 111;
int ans[50][50];
int dx[sz], dy[sz];
int main()
{
ios_base::sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
int x[K], y[K], t[K];
for (int i = 0; i < K; i++)
{
cin >> y[i] >> x[i] >> t[i];
x[i]--;
y[i]--;
}
dx[0] = dy[0] = 0;
int tim = 1;
int a = 0;
int b = 0;
for (int d = 1; d <= 50; d++)
{
b++;
a--;
for (int c = 0; c <= 2 * d - 1; c++)
{
a++;
dx[tim] = a;
dy[tim] = b;
tim++;
}
for (int c = 0; c <= 2 * d - 1; c++)
{
b--;
dx[tim] = a;
dy[tim] = b;
tim++;
}
for (int c = 0; c <= 2 * d - 1; c++)
{
a--;
dx[tim] = a;
dy[tim] = b;
tim++;
}
for (int c = 0; c <= 2 * d - 1; c++)
{
b++;
dx[tim] = a;
dy[tim] = b;
tim++;
}
}
for (int id = 0; id < sz; id++)
{
for (int i = 0; i < K; i++)
{
int yy = -dy[id] + y[i];
int xx = -(t[i] * 2 - 1) * (dx[id]) + x[i];
if (xx >= 0 && xx < M && yy >= 0 && yy < N && ans[yy][xx] == 0)
ans[yy][xx] = id + 1;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
cout << ans[i][j] << " ";
}
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
147 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |