Submission #237529

#TimeUsernameProblemLanguageResultExecution timeMemory
237529NONAMESpirale (COCI18_spirale)C++17
80 / 80
40 ms384 KiB
#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 timeMemoryGrader output
Fetching results...