답안 #83506

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83506 2018-11-08T14:33:56 Z charlies_moo Spirale (COCI18_spirale) C++14
80 / 80
57 ms 588 KB
# include <iostream>
# include <fstream>
using namespace std;

int main(){
    istream &fin = cin;
    ostream &fout = cout;
    int n, m, k, inf, x, y, t, i, j, p;
    fin >> n >> m >> k;
    inf = n * m * 10;
    int arr[n][m];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            arr[i][j] = inf;
        }
    }
    for(p=1;p<=k;p++){
        int num, counter, length, direction;
        num = 1;
        length = 1;
        direction = -1;
        fin >> x >> y >> t;
        x -= 1;
        y -= 1;
        if(t==0){
            t=1;
        }
        else{
            t=-1;
        }
        arr[x][y] = num;
        counter = 1;
        while(counter < (n * m)){
            for(i=1;i<=length;i++){
                num += 1;
                x += direction;
                if(x<0||x>=n||y<0||y>=m){
                    continue;
                }
                if(arr[x][y] > num){
                    arr[x][y] = num;
                }
                counter += 1;
            }
            direction = 0 - direction;
            for(i=1;i<=length;i++){
                num += 1;
                y += direction * t;
                if(x<0||x>=n||y<0||y>=m){
                    continue;
                }
                if(arr[x][y] > num){
                    arr[x][y] = num;
                }
                counter += 1;
            }
            length += 1;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            fout << arr[i][j] << " ";
        }
        fout << endl;
    }
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 528 KB Output is correct
4 Correct 2 ms 528 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Correct 3 ms 528 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 57 ms 564 KB Output is correct
10 Correct 2 ms 588 KB Output is correct