# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1018554 | vjudge1 | Spirale (COCI18_spirale) | C++17 | 57 ms | 572 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > create(int n)
{
int c = n / 2;
vector<vector<int> > ans(n, vector<int> (n));
vector<pair<int,int> > moves(n * n + 1, {2, 2});
for(int i = 1; i <= n; i += 2)
moves[i * i] = {-1, 0}, moves[i * i + 1] = {0, 1};
for(int i = 2; i <= n; i += 2)
moves[i * i] = {1, 0}, moves[i * i + 1] = {0, -1};
for(int i = 1; i < n; i ++)
{
int idx = (i * i + (i + 1) * (i + 1) + 1) / 2;
if(i % 2 == 1)
moves[idx] = {1, 0};
else
moves[idx] = {-1, 0};
}
for(int i = 1; i <= n * n; i ++)
if(moves[i].first == 2) moves[i] = moves[i - 1];
int x = c, y = c;
for(int i = 1; i <= n * n; i++)
{
ans[x][y] = i;
x += moves[i].first;
y += moves[i].second;
}
return ans;
}
int main()
{
int n, m, k;
cin >> n >> m >> k;
int ans[n][m];
for(int i = 0; i < n; i ++)
for(int j = 0; j < m ; j ++)
ans[i][j] = 1e8;
while(k--)
{
int x, y, d;
cin >> x >> y >> d;
x--, y--; // how much row and cols do we need
int sz = max(max(x, n - x - 1), max(y, m - y - 1)) * 2 + 1;
vector<vector<int> > grid = create(sz);
if(d)
for(vector<int> &vec : grid)
reverse(vec.begin(), vec.end());
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
{
int x1 = i - x + sz / 2, y1 = j - y + sz / 2;
ans[i][j] = min(ans[i][j], grid[x1][y1]);
}
}
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
cout << ans[i][j] << " \n"[j == m - 1];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |