회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
노가다를 하더라도 풀고싶어요(70% 메모리초과)
17114번 - 하이퍼 토마토
joomongogo
7달 전
0
int 배열이 10^6개일텐데, 왜 메모리 초과에요?
#include <bits/stdc++.h> using namespace std; int ***********arr; int ***********chk; int n, m, h, p, qq, r, s, t, u, v, w; queue<tuple<int, int, int, int, int, int, int, int, int, int, int>> state; queue<tuple<int, int, int, int, int, int, int, int, int, int, int, int>> q; int dn[] = {1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int dm[] = {0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int dh[] = {0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int dp[] = {0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int dqq[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int dr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int ds[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0}; int dt[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0}; int du[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0}; int dv[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0}; int dw[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1}; //n, m, h, p, qq, r, s, t, u, v, w void push(int N, int M, int H, int P, int QQ, int R, int S, int T, int U, int V, int W, int cnt) { if (N < 0 || M < 0 || H < 0 || P < 0 || QQ < 0 || R < 0 || S < 0 || T < 0 || U < 0 || V < 0 || W < 0 ||N >= n || M >= m || H >= h || P >= p || QQ >= qq || R >= r || S >= s || T >= t || U >= u || V >= v || W >= w) return; if (arr[N][M][H][P][QQ][R][S][T][U][V][W] != 0) return; chk[N][M][H][P][QQ][R][S][T][U][V][W] = 1; arr[N][M][H][P][QQ][R][S][T][U][V][W] = 1; q.push({N, M, H, P, QQ, R, S, T, U, V, W, cnt}); return; } int bfs() { while (!state.empty()) { auto [N, M, H, P, QQ, R, S, T, U, V, W] = state.front(); state.pop(); q.push({N, M, H, P, QQ, R, S, T, U, V, W, 0}); chk[N][M][H][P][QQ][R][S][T][U][V][W] = 1; } int ans = 0; while (!q.empty()) { auto [N, M, H, P, QQ, R, S, T, U, V, W, cnt] = q.front(); q.pop(); ans = max(ans, cnt); for (int i = 0; i < 22; i++) { push(N + dn[i], M + dm[i], H + dh[i], P + dp[i], QQ + dqq[i], R + dr[i], S + ds[i], T + dt[i], U + du[i], V + dv[i], W + dw[i], cnt + 1); } } for (int a = 0; a < n; a++) { for (int b = 0; b < m; b++) { for (int c = 0; c < h; c++) { for (int d = 0; d < p; d++) { for (int e = 0; e < qq; e++) { for (int f = 0; f < r; f++) { for (int g = 0; g < s; g++) { for (int h1 = 0; h1 < t; h1++) { for (int i = 0; i < u; i++) { for (int j = 0; j < v; j++) { for (int k = 0; k < w; k++) { if (arr[a][b][c][d][e][f][g][h1][i][j][k] == 0) return -1; } } } } } } } } } } } return ans; } int main() { cin >> m >> n >> h >> p >> qq >> r >> s >> t >> u >> v >> w; arr = new int**********[n]; chk = new int**********[n]; for (int a = 0; a < n; a++) { arr[a] = new int*********[m]; chk[a] = new int*********[m]; for (int b = 0; b < m; b++) { arr[a][b] = new int********[h]; chk[a][b] = new int********[h]; for (int c = 0; c < h; c++) { arr[a][b][c] = new int*******[p]; chk[a][b][c] = new int*******[p]; for (int d = 0; d < p; d++) { arr[a][b][c][d] = new int******[qq]; chk[a][b][c][d] = new int******[qq]; for (int e = 0; e < qq; e++) { arr[a][b][c][d][e] = new int*****[r]; chk[a][b][c][d][e] = new int*****[r]; for (int f = 0; f < r; f++) { arr[a][b][c][d][e][f] = new int****[s]; chk[a][b][c][d][e][f] = new int****[s]; for (int g = 0; g < s; g++) { arr[a][b][c][d][e][f][g] = new int***[t]; chk[a][b][c][d][e][f][g] = new int***[t]; for (int h1 = 0; h1 < t; h1++) { arr[a][b][c][d][e][f][g][h1] = new int**[u]; chk[a][b][c][d][e][f][g][h1] = new int**[u]; for (int i = 0; i < u; i++) { arr[a][b][c][d][e][f][g][h1][i] = new int*[v]; chk[a][b][c][d][e][f][g][h1][i] = new int*[v]; for (int j = 0; j < v; j++) { arr[a][b][c][d][e][f][g][h1][i][j] = new int[w]; chk[a][b][c][d][e][f][g][h1][i][j] = new int[w]; } } } } } } } } } } for(int a = 0; a < w; a++) { for(int b = 0; b < v; b++) { for(int c = 0; c < u; c++) { for(int d = 0; d < t; d++) { for(int e = 0; e < s; e++) { for(int f = 0; f < r; f++) { for(int g = 0; g < qq; g++) { for(int h1 = 0; h1 < p; h1++) { for(int i = 0; i < h; i++) { for(int j = 0; j < m; j++) { for(int k = 0; k < n; k++) { cin >> arr[k][j][i][h1][g][f][e][d][c][b][a]; if (arr[k][j][i][h1][g][f][e][d][c][b][a] == 1) { state.push({k, j, i, h1, g, f, e, d, c, b, a}); } } } } } } } } } } } } cout << bfs(); }
joomongogo
7달 전
2
풀었습니다! 포인터가 문제였네요.
댓글을 작성하려면
로그인
해야 합니다.
joomongogo 7달 전
int 배열이 10^6개일텐데, 왜 메모리 초과에요?