Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp] 민코딩 구현의 탑 5번 - 오목 #36

Merged
merged 2 commits into from
Aug 2, 2023

Conversation

minjae9610
Copy link
Member

@minjae9610 minjae9610 commented Jul 27, 2023

📣 Related Issue

close #

🌁 Background

민코딩 문제풀이

👩‍💻 Contents

[알고리즘 탑] 구현의 탑 5번 - 오목 (백준 2615 - Silver 1 동일하기 때문에 문제 정보는 백준으로 대체)

image
image

#include <iostream>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int field[19][19];
	for (auto& row : field)
		for (int& element : row)
			cin >> element;

	int row_check[19] = { 0, };
	int col_check[19] = { 0, };
	int diag1_check[37] = { 0, };
	int diag2_check[37] = { 0, };

	for (int row = 18; row >= 0; --row) {
		for (int col = 18; col >= 0; --col) {
			if (field[row][col] == 0) {
				row_check[row] = 0;
				col_check[col] = 0;
				diag1_check[row + col] = 0;
				diag2_check[row - col + 18] = 0;
			}
			else if (field[row][col] == 1) {
				row_check[row] = (row_check[row] > 0 ? row_check[row] + 1 : 1);
				col_check[col] = (col_check[col] > 0 ? col_check[col] + 1 : 1);
				diag1_check[row + col] = (diag1_check[row + col] > 0 ? diag1_check[row + col] + 1 : 1);
				diag2_check[row - col + 18] = (diag2_check[row - col + 18] > 0 ? diag2_check[row - col + 18] + 1 : 1);
			}
			else if (field[row][col] == 2) {
				row_check[row] = (row_check[row] < 0 ? row_check[row] - 1 : -1);
				col_check[col] = (col_check[col] < 0 ? col_check[col] - 1 : -1);
				diag1_check[row + col] = (diag1_check[row + col] < 0 ? diag1_check[row + col] - 1 : -1);
				diag2_check[row - col + 18] = (diag2_check[row - col + 18] < 0 ? diag2_check[row - col + 18] - 1 : -1);
			}
			if (row_check[row] == 5 || col_check[col] == 5 || diag1_check[row + col] == 5 || diag2_check[row - col + 18] == 5) {
				if (row_check[row] == 5 && col > 0 && field[row][col - 1] == 1)
					continue;
				if (col_check[col] == 5 && row > 0 && field[row - 1][col] == 1)
					continue;
				if (diag1_check[row + col] == 5 && row > 0 && col < 18 && field[row - 1][col + 1] == 1)
					continue;
				if (diag2_check[row - col + 18] == 5 && row > 0 && col > 0 && field[row - 1][col - 1] == 1)
					continue;
				cout << 1 << '\n';
			}
			else if (row_check[row] == -5 || col_check[col] == -5 || diag1_check[row + col] == -5 || diag2_check[row - col + 18] == -5) {
				if (row_check[row] == -5 && col > 0 && field[row][col - 1] == 2)
					continue;
				if (col_check[col] == -5 && row > 0 && field[row - 1][col] == 2)
					continue;
				if (diag1_check[row + col] == -5 && row > 0 && col < 18 && field[row - 1][col + 1] == 2)
					continue;
				if (diag2_check[row - col + 18] == -5 && row > 0 && col > 0 && field[row - 1][col - 1] == 2)
					continue;
				cout << 2 << '\n';
			}
			else
				continue;
			if (diag1_check[row + col] == 5 || diag1_check[row + col] == -5) {
				row += 4;
				col -= 4;
			}
			cout << row + 1 << ' ' << col + 1 << '\n';
			return 0;
		}
	}
	cout << 0 << '\n';

	return 0;
}

📱 Screenshot

image
image

📝 Review Note

이거 맞나..?

📬 Reference

@minjae9610 minjae9610 requested a review from a team as a code owner July 27, 2023 16:02
@minjae9610 minjae9610 requested review from Yg-Hong and 3o14 and removed request for a team July 27, 2023 16:02
Copy link
Contributor

@Yg-Hong Yg-Hong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 말하는 감자는 오늘 월말고사를 보고서야 리뷰를 보고 깨달음을 얻습니다...
다들 팔방탐색으로 도전하는 와중에 민재님 DAT로 풀어나가는게 인상적입니다. 사실 팔방탐색으로 구현해도 시간복잡도는 O(n)으로 나올 수 있겠지만 DAT를 활용해야 반복잡업을 줄일 수 있군요...
바둑판 사이즈가 n으로 커진다면 팔방탐색은 O(n^3)까지 갈 수 있어서 DAT(O(n^2))를 알아두어야 할 것 같습니다 :)
처음에는 이해가 어려워서 Java로 코드를 한줄한줄 바꿔보면서 공부했어요!! 덕분에 좋은 공부 됐습니다... 늘 감사드려용 💯 💯

@3o14
Copy link
Member

3o14 commented Aug 2, 2023

코드 잘 보았습니다!! c++이 너무 익숙치 않아서 리뷰가 늦어진 점 죄송합니다 🙇🏻‍♀️
다른 분들 대부분 사방 혹은 팔방으로 접근해서 풀었던데 이렇게 푸는 방식도 있네요!
위에 리뷰어 말씀 보니 DAT라고 하는군요 새롭게 배웠습니다!
예외 처리때문에 반복되는 코드가 많이 보이는데 이건 이것대로 오히려 편하게 읽히는 부분이 있네요!
수고하셨습니다 !!

@minjae9610
Copy link
Member Author

코드 잘 보았습니다!! c++이 너무 익숙치 않아서 리뷰가 늦어진 점 죄송합니다 🙇🏻‍♀️
다른 분들 대부분 사방 혹은 팔방으로 접근해서 풀었던데 이렇게 푸는 방식도 있네요!
위에 리뷰어 말씀 보니 DAT라고 하는군요 새롭게 배웠습니다!
예외 처리때문에 반복되는 코드가 많이 보이는데 이건 이것대로 오히려 편하게 읽히는 부분이 있네요!
수고하셨습니다 !!

@3o14 본문의 리뷰노트에 적어둔 한마디를 보시면 아시겠지만.. 풀면서 너무 하드코딩 느낌 나서 슬펐습니다 ㅠㅠ
어프루브 부탁드립니다 :)

@3o14 3o14 closed this Aug 2, 2023
@3o14 3o14 reopened this Aug 2, 2023
@3o14 3o14 merged commit 2da0bae into main Aug 2, 2023
1 check passed
@3o14 3o14 deleted the algo/minjae9610/mincoding_implement_5 branch August 2, 2023 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants