# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
237529 | NONAME | Spirale (COCI18_spirale) | C++17 | 40 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define el '\n'
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
//const int steps[2][4][2] = {{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}, {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}};
const int steps[2][4][2] = {{{0, -1}, {-1, 0}, {0, 1}, {1, 0}}, {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}};
const int up[2] = {1, 3};
int n, m, q, a[100][100];
void paint(int x, int y, int t) {
int total = 0, nm = 1, cnt = 1, i = 1, tt = 0;
while (1) {
tt++;
int f = 1;
int cur = cnt + (i == up[cnt % 2]);
for (int j = 0; j < cur; ++j, ++nm) {
if (x >= 0 && y >= 0 && x < n && y < m) {
f = 0;
a[x][y] = min(a[x][y], nm);
}
x += steps[t][i][0];
y += steps[t][i][1];
}
total += f;
if (total == 4)
break;
if (tt == 2)
cnt++, tt = 0;
if (i + 1 == 4)
total = 0;
i = (i + 1) % 4;
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
a[i][j] = 10000;
while (q--) {
int x, y, t;
cin >> x >> y >> t;
x--, y--;
paint(x, y, t);
}
for (int i = 0; i < n; ++i, cout << el)
for (int j = 0; j < m; ++j)
cout << a[i][j] << ' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |