/************************************************* 짝수번: A x A x A x A = (A x A) x (A x A) 홀수번: A x A x A x A x A = (A x A) x (A x A) x A *************************************************/ #include using namespace std; long long int dc(int a, int b, int c) { if (b == 1) return a % c;//base condition: A의 1승 if (b % 2) return dc(a, b / 2, c) * dc(a, b / 2, c) % c * a % c; else return dc(a, b / 2, c..
![[백준 14600번] 샤워실 바닥 갈기 (Small) (C++)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fd9kbU1%2Fbtszcp532ZU%2F0IU0F2zPYqpLKKXyZakGbK%2Fimg.png)
#include using namespace std; int num; int map[4][4]; bool check(int x1, int y1, int x2, int y2) { for (int i = x1; i > m >> n; map[m-1][n-1] = -1; int siz = (1 = 0; i--, cout
![[백준 9920번] image (C++)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FemtxwX%2FbtsyTutSZEN%2FdqA20Or9ffZNrgLGcKrwc0%2Fimg.png)
//white: 0, black: 1 #define SIZE 64 #include using namespace std; int dat; int cnt; int map[SIZE][SIZE]; // change - true, not change - false bool check(int x1, int y1, int x2, int y2) { dat = map[x1][y1]; for (int i = x1; i < x2; i++) { for (int j = y1; j < y2; j++) { if (dat != map[i][j]) return true; } } return false; } int dc(int size, int x, int y) { if (size == 1) return 2; if (!check(x, ..
![[백준 10830번] 행렬 제곱 (C++)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbrOASj%2FbtsyU9a4KFZ%2F4aAHBvsjchCFGUEHTJduC1%2Fimg.png)
![[백준 1780번] 종이의 개수 (C++)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FDR0q7%2FbtsyV1cLLWG%2FkKsum2AxOBQsAWP3PJ5YMk%2Fimg.png)
//white: 0, black: 1 #define SIZE 2187 #include #include #include using namespace std; int dat; // -1, 0, 1 int cnt[3]; // -1: 0, 0: 1, 1: 2 int map[SIZE][SIZE]; // change - true, not change - false bool check(int x1, int y1, int x2, int y2) { dat = map[x1][y1]; for (int i = x1; i < x2; i++) { for (int j = y1; j < y2; j++) { if (dat != map[i][j]) return true; } } return false; } void dc(int size..
![[백준 1992번] 쿼드트리 (C++)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FlG3JA%2FbtsyTof1ts5%2FPDOhKl3iFtc68PkW6CWock%2Fimg.png)
//white: 0, black: 1 #define SIZE 64 #include #include #include using namespace std; char col; char map[SIZE][SIZE]; // change - true, not change - false bool check(int x1, int y1, int x2, int y2) { col = map[x1][y1]; for (int i = x1; i < x2; i++) { for (int j = y1; j < y2; j++) { if (col != map[i][j]) return true; } } return false; } void dc(int size, int x, int y) { if (size == 1) { cout str; ..
![[백준 2630번] 색종이 만들기 (C++)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbmHMom%2FbtsyTYgAdr6%2FBl4jO1QLSsK7LQfuRcV1lk%2Fimg.png)
//white: 0, black: 1 #define SIZE 128 #define F first #define S second #define X dir_x #define Y dir_y #include using namespace std; int col; int cnt[2]; //index 0: white, 1:blue int map[SIZE][SIZE]; // change - true, not change - false bool check(int x1, int y1, int x2, int y2) { col = map[x1][y1]; for (int i = x1; i < x2; i++) { for (int j = y1; j < y2; j++) { if (col != map[i][j]) return true..
![[백준 1074번] Z (C++)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FePMiyC%2FbtsyIGGSypj%2FPeWKpTyFDuO32jRsUaeMQ0%2Fimg.png)
1. 문제 https://www.acmicpc.net/problem/1074 1074번: Z 한수는 크기가 2N × 2N인 2차원 배열을 Z모양으로 탐색하려고 한다. 예를 들어, 2×2배열을 왼쪽 위칸, 오른쪽 위칸, 왼쪽 아래칸, 오른쪽 아래칸 순서대로 방문하면 Z모양이다. N > 1인 경우, 배열을 www.acmicpc.net 2. 풀이 단순히 모든 칸을 한칸씩 다 탐색했더니 시간초과가 나왔다. N의 최대값을 살펴보니 15이다. 최대 size는 2의 15승이므로 32,768이 된다. 즉, 최대넓이는 32,768 x 32,768 = 1,073,741.824로 10억이 넘어간다. 결국 10억이 넘는 칸을 모두 탐색할 경우 대충 10초가 나온다.(1억번 탐색하면 약 1초가 나오므로) 따라서 구역을 확인 후..