Submission #237529

# Submission time Handle Problem Language Result Execution time Memory
237529 2020-06-07T07:34:53 Z NONAME Spirale (COCI18_spirale) C++17
80 / 80
40 ms 384 KB
#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
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 40 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct