회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
알고스팟 문제 어느부분이 틀린건지 도저히 모르겠습니다
1261번 - 알고스팟
malmang
5년 전
0
어디서 오류가 나는건지 전혀모르겠습니다..ㅜ
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include<algorithm> #include<queue> #include<functional> #include<string> using namespace std; priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq; int n,m; int map[101][101]; int visited[101][101]={0, }; int dr[]={-1,0,1,0}; int dc[]={0,1,0,-1}; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ cin>>map[i][j]; } } pq.push({0,{0,0}}); visited[0][0]=1; while(!pq.empty()){ int r=pq.top().second.first; int c=pq.top().second.second; int cnt=pq.top().first; //cout<<r<<" "<<c<<" "<<cnt<<endl; pq.pop(); if(r==n-1 && c == m-1){ cout<<cnt; break; } for(int i=0; i<4; i++){ int nr=r+dr[i]; int nc=c+dc[i]; if(nr>=0 && nc>=0 && nr<n && nc<m) { if(map[nr][nc]==1 &&visited[nr][nc]==0){ visited[nr][nc]==1; pq.push({cnt+1,{nr,nc}}); } if(map[nr][nc]==0 &&visited[nr][nc]==0){ visited[nr][nc]==1; pq.push({cnt,{nr,nc}}); } } } } }
malmang
5년 전
0
이 코드랑 비교해봤을때 비슷한거 같은데 왜 제 코드는 안돌아갈까요...
#include <iostream> #include <string> #include <vector> #include <queue> #include <functional> #include <algorithm> using namespace std; const int MAX = 100; typedef struct { int y, x; }Dir; Dir moveDir[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; int M, N; string input[MAX]; bool visited[MAX][MAX]; int BFS(void) { //깨드린 블록을 기준으로 최소 힙 선언 priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq; pq.push({ 0, {0, 0} }); visited[0][0] = true; while (!pq.empty()) { int y = pq.top().second.first; int x = pq.top().second.second; int block = pq.top().first; pq.pop(); if (y == N - 1 && x == M - 1) return block; for (int i = 0; i < 4; i++) { int nextY = y + moveDir[i].y; int nextX = x + moveDir[i].x; if (0 <= nextY && nextY < N && 0 <= nextX && nextX < M) { if (!visited[nextY][nextX]) { if (input[nextY][nextX] == '1') pq.push({ block + 1,{ nextY, nextX } }); else pq.push({ block, {nextY, nextX} }); visited[nextY][nextX] = true; } } } } } int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cin >> M >> N; for (int i = 0; i < N; i++) cin >> input[i]; cout << BFS() << "\n"; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
malmang 5년 전
어디서 오류가 나는건지 전혀모르겠습니다..ㅜ