Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 백준
- java
- java정리
- 개발
- 코딩테스트
- 주가예측
- SNS
- 풀스택프레임워크
- 자바독학
- 코딩독학
- Python
- C++
- 코스닥
- 프로그래밍
- 프로그래머스
- Reflex
- 프로그램
- 개발자
- 자바
- frontend
- Project
- 이웃한 칸
- backend
- 사물인터넷
- 모의 주식
- 빅데이터
- 코딩
- 개인프로젝트
- 코테
- 자바정리
Archives
- Today
- Total
Creative Code
[7569번]토마토 본문
https://www.acmicpc.net/problem/7569
7569번: 토마토
첫 줄에는 상자의 크기를 나타내는 두 정수 M,N과 쌓아올려지는 상자의 수를 나타내는 H가 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M ≤ 100, 2 ≤ N ≤ 100,
www.acmicpc.net
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <tuple>
using namespace std;
int arr[101][101][101];
int answer;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int M, N, H;
cin >> M >> N >> H;
answer = 0;
queue<tuple<int,int,int>>q;
vector<tuple<int, int, int>>direct = { {0,0,1},{0,0,-1},{1,0,0},{0,1,0},{-1,0,0},{0,-1,0} };
for (int k = 0; k < H; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
int num;
cin >> num;
arr[i][j][k] = num;
if (num == 1) {
q.push(make_tuple(i, j, k));
}
}
}
}
int index = 0;
while (true) {
queue<tuple<int, int,int>>pq;
while (!q.empty()) {
int x = get<0>(q.front());
int y = get<1>(q.front());
int z = get<2>(q.front());
q.pop();
for (int i = 0; i < 6; i++) {
int nx = x + get<0>(direct[i]);
int ny = y + get<1>(direct[i]);
int nz = z + get<2>(direct[i]);
if (nx == N || ny == M || nz == H || nx == -1 || ny == -1 || nz == -1) {
continue;
}
else if (arr[nx][ny][nz] == 0) {
arr[nx][ny][nz] = 1;
pq.push(make_tuple(nx, ny, nz));
}
}
}
q = pq;
if (pq.empty()) {
break;
}
index++;
}
for (int k = 0; k < H; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (arr[i][j][k] == 0) {
index = -1;
break;
}
}
}
}
cout << index;
}
'백준 문제풀이' 카테고리의 다른 글
[10026번]적록색약 (0) | 2023.09.24 |
---|---|
[7576번]토마토 (0) | 2023.09.24 |
[5430번]AC (0) | 2023.09.24 |
[2166번]다각형의 면적 (0) | 2023.09.24 |
[2096번]내려가기 (0) | 2023.09.24 |