Submission #293484

# Submission time Handle Problem Language Result Execution time Memory
293484 2020-09-08T06:31:55 Z 7_7_7 Spirale (COCI18_spirale) C++17
80 / 80
53 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e1 + 7;

int n;
int m;
int k;
int cnt;
int a[N][N];
void upd(int x, int y, int val){
    if(1 <= x && x <= n){
        if(1 <= y && y <= m){
            cnt ++;
            a[x][y] = min(a[x][y], val);
        }
    }
}
vector<vector<int>> t{
    {2, 3, 1, 0},
    {3, 2, 0, 1}
};
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> m >> k;
    memset(a, 64, sizeof a);
    for(int i = 1; i <= k; i ++){
        int x, y, type, dir = 0, val = 1, len = 1;
        cin >> x >> y >> type;
        cnt = 0;
        upd(x, y, val);
        while(cnt < n * m){
            for(int i = 1; i <= len; i ++){
                val ++;
                if(dir == 0) x --;
                if(dir == 1) x ++;
                if(dir == 2) y ++;
                if(dir == 3) y --;
                upd(x, y, val);
            }
            if(dir == 2 || dir == 3) len ++;
            dir = t[type][dir];
        }
    }
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            cout << a[i][j] << " \n"[j == m];
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 53 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct