2992KB, 32ms

  • 구현 문제
  • 주의점
    • 회오리 배열
#include <iostream>
#include <iomanip>

#define MAX 499
using namespace std;

int dy[4][10] = { {-1,1,-2,2,0,-1,1,-1,1,0},
				 {1,1,0,0,-2,0,0,-1,-1,-1},
				 {-1,1,-2,2,0,-1,1,-1,1,0},
				 {-1,-1,0,0,2,0,0,1,1,1} }; // 우상좌하
int dx[4][10] = { {-1,-1,0,0,2,0,0,1,1,1},
				 {-1,1,-2,2,0,-1,1,-1,1,0},
				 {1,1,0,0,-2,0,0,-1,-1,-1},
				 {-1,1,-2,2,0,-1,1,-1,1,0} };
int ratio[9] = { 1,1,2,2,5,7,7,10,10};

int dir_dy[4] = { 0,-1,0,1 }, dir_dx[4] = { 1,0,-1,0 };

int N;
int map[MAX][MAX] = {};
int y, x;

int result = 0;

void gol() {
	int twice = 0, cnt = 1, count = 0;
	y = N / 2; x = N / 2 - 1;
	int dir = 2;

	while (!(y == 0 && x == -1)) {
		int minus = 0, new_y, new_x;
		for (int i = 0; i < 9; i++) {
			new_y = y + dy[dir][i]; new_x = x + dx[dir][i];
			minus += map[y][x] * ratio[i] / 100;

			if (new_y >= N || new_x >= N || new_y < 0 || new_x < 0)
				result += map[y][x] * ratio[i] / 100;	
			else map[new_y][new_x] += map[y][x] * ratio[i] / 100;
		}

		new_y = y + dy[dir][9]; new_x = x + dx[dir][9];
		if (new_y >= N || new_x >= N || new_y < 0 || new_x < 0)
			result += map[y][x] - minus;
		else map[new_y][new_x] += map[y][x] - minus;

		map[y][x] = 0;

		count++;
		
		if (cnt == count) {
			twice++;
			dir = (dir + 5) % 4;
			count = 0; 
			if (twice == 2) {
				cnt++;
				twice = 0;
			}
		}
		y += dir_dy[dir]; x += dir_dx[dir];
	}
}

void input() {
	cin >> N;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			cin >> map[i][j];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	input();
	gol();

	cout << result;

}

'coding > baekjoon_codingstudy' 카테고리의 다른 글

21608 상어 초등학교  (0) 2022.10.11
21610 마법사 상어와 비바라기  (0) 2022.10.11
17825 주사위 윷놀이  (0) 2022.10.10
20061 모노미노도미노2  (0) 2022.10.06
12100 2048(Easy)  (0) 2022.10.03

+ Recent posts