[백준] 2206 벽 부수고 이동하기 C++
메모리 초과 난 코드#include #include using namespace std;int x, y,xx,yy;int dy[4] = { 0,0,1,-1 }, dx[4] = { 1,-1,0,0 };int arr[1005][1005] ,visited[1005][1005], dist[1005][1005],wall[1005][1005];queue> q;void bfs() { while (1) { if (q.empty()) { return; } int h = q.front().first; int w = q.front().second; visited[h][w] = 1; q.pop(); for (int i = 0; i = 0 && yy = 0 && xx = 0 && yy = 0 && xx > y ..
더보기
[백준] 7659 토마토 C++
두번째 코드가 가장 이상적인 코드#include #include #include using namespace std;queue>> q;int m,n,h;int arr[105][105][105],days[105][105][105];int dn[4]={0,0,1,-1}, dm[4]={1,-1,0,0},dh[2]={1,-1};bool flag_stop=false;void bfs(){ while(1){ if(q.empty()) break; int hh=q.front().first; int nn=q.front().second.first; int mm=q.front().second.second; q.pop(); ..
더보기
SWEA) 1859. 백만 장자 프로젝트
#include using namespace std;int arr[1000005];//arr배열을 지역변수에 선언하면 Segmentation fault error가 발생하는 이유//크기가 큰 배열을 지역변수에 할당하면 힙메모리 영역 침범 가능성이 있다.//고로 크기가 큰 배열은 전역변수 공간인 DATA영역에 선언하는 것이 좋다int main() { int T,test_case; int n,maxnum; long int sum=0; //long int형으로 해야하는 이유 : n은 최대 1,000,000 가능 //arr[i]는 최대 10,000가능 n-1일동안 arr[i]가 전부 1이고 n번째에 10,000이면 //sum은 999,999 * 9,999 = 9,998,990,..
더보기