
처음에는 xcode가 자동으로 업데이트가 되면서 컴파일러가 꼬였는줄 알았다. 근데 동일한 환경에서 다른 파일은 잘 실행되어서 의문이 생김.
#include <bits/stdc++.h>
using namespace std;
int board[1002][1002];
int bwall[1002][1002];
int dis[1002][1002];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); // cin.tie(0);
freopen("input.txt", "rt", stdin);
cin >> n >> m;
for (int i = 0; i < n; i++) {
fill(dis[i], dis[i] + m, -1);
}
queue<tuple<int, int, int>> q;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
board[i][j] = s[j] - '0';
}
}
q.push({0, 0, 0});
dis[0][0] = 1;
int flag = 0;
while (!q.empty()) {
auto cur = q.front();
int curx, cury, wall;
tie(curx, cury, wall) = cur;
q.pop();
if (curx == n - 1 && cury == m - 1) {
cout << dis[curx][cury];
flag = 1;
break;
}
for (int i = 0; i < 4; i++) {
int nx = curx + dx[i];
int ny = cury + dy[i];
if (nx < 0 || nx > n - 1 || ny < 0 || ny > m - 1) continue;
// if (dis[nx][ny] > -1 && bwall[nx][ny] == 1 && wall == 0)
if ((dis[nx][ny] > -1 && wall == 1) || bwall[nx][ny] == 1) continue;
if (board[nx][ny] == 1) {
if (wall == 0) {
bwall[nx][ny] = 1;
dis[nx][ny] = dis[curx][cury] + 1;
q.push({nx, ny, 1});
// cout << "wall o : " << nx << " " << ny << " " << 1 << " " << dis[nx][ny] << '\n';
} else
continue;
} else {
dis[nx][ny] = dis[curx][cury] + 1;
q.push({nx, ny, wall});
if (wall == 0) bwall[nx][ny] = 1;
// cout << "wall x : " << nx << " " << ny << " " << wall << " " << dis[nx][ny] << '\n';
}
}
}
if (flag == 0) cout << "-1\n";
return 0;
}#include <time.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef tuple<int, int, int> ti3;
//위부터 시계반대반향. 위 오른쪽 아래 왼쪽
const int dr[4] = { -1, 0, 1, 0 };
const int dc[4] = { 0, 1, 0, -1};
const int ddr[8] = { 0,0,1,1,1,-1,-1,-1 }, ddc[8] = { 1,-1,1,0,-1,1,0,-1 };
bool OOB(ll x, ll y, ll N, ll M) { return 0 > x || x >= N || 0 > y || y >= M; }
#define F first
#define S second
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define pb push_back
#define pf1(a) cout << (a) << ' '
#define pf2(a,b) cout << (a) << ' ' << (b) << ' '
#define pf3(a,b,c) cout << (a) << ' ' << (b) << ' '<< (c) << ' '
#define pf4(a,b,c,d) cout << (a) << ' ' << (b) << ' '<< (c) << ' '<< (d) << ' '
#define pf5(a,b,c,d,e) cout << (a) << ' ' << (b) << ' '<< (c) << ' '<< (d) << ' '<< (e) << ' '
#define pf6(a,b,c,d,e,f) cout << (a) << ' ' << (b) << ' '<< (c) << ' '<< (d) << ' '<< (e) << ' ' << (f) << ' '
#define pf0l() cout << '\n'
#define pf1l(a) cout << (a) << '\n'
#define pf2l(a,b) cout << (a) << ' ' << (b) << '\n'
#define pf3l(a,b,c) cout << (a) << ' ' << (b) << ' '<< (c) << '\n'
#define pf4l(a,b,c,d) cout << (a) << ' ' << (b) << ' '<< (c) << ' '<< (d) << '\n'
#define pf5l(a,b,c,d,e) cout << (a) << ' ' << (b) << ' '<< (c) << ' '<< (d) << ' '<< (e) << '\n'
#define pf6l(a,b,c,d,e,f) cout << (a) << ' ' << (b) << ' '<< (c) << ' '<< (d) << ' '<< (e) << ' ' << (f) << '\n'
#define pfvec(V) for(auto const &t : V) pf1(t)
#define pfvecl(V) for(auto const &t : V) pf1(t); pf0l()
#define sf1(a) cin >> a
#define sf2(a,b) cin >> a >> b
#define sf3(a,b,c) cin >> a >> b >> c
#define sf4(a,b,c,d) cin >> a >> b >> c >> d
#define sf5(a,b,c,d,e) cin >> a >> b >> c >> d >> e
#define sf6(a,b,c,d,e,f) cin >> a >> b >> c >> d >> e >> f
// const int MOD = 1000'000'005;
const int MAX_N = 100'005;
const int MAX_M = 500'005;
const int INF = 0xfffffff;
int N, M, P, Q, T, K, V, E;
vector<pii> adj[MAX_N]; //비용, 정점
int interview[MAX_N], d[MAX_N];
// int solve(int st, int en) {
// }
void code() {
fill(d, d+N+1, INF);
priority_queue<pii, vector<pii>, greater<pii>> pq;
rep(i, 0, K) {
int u = interview[i];
d[u] = 0;
pq.push({d[u], u});
}
int u, v, w, dw;
while(!pq.empty()) {
tie(w, u) = pq.top(); pq.pop();
if(d[u] != w) continue;
for(auto nxt : adj[u]) {
tie(dw, v) = nxt;
if(d[v] <= d[u] + dw) continue;
d[v] = d[u] + dw;
pq.push({d[v], v});
}
}
rep(i, 0, N) pf1(d[i]);
}
void input() {
sf3(N, M, K);
int u, v, c;
rep(i, 0, M) {
sf3(u, v, c);
adj[u].pb({c, v});
}
rep(i, 0, K) {
sf1(interview[i]);
}
}
void with_time_check() {
freopen("input.txt", "rt", stdin);
clock_t start, end; double result;
start = clock(); // 시간 측정 시작
cout << "=============\n";
input();
code();
end = clock(); // 시간 측정 끝
result = (double)(end - start);
cout << "\n=============\n총 걸린 시간 : " << result << "ms\n"; // 결과 출력
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
with_time_check();
// input(); code();
return 0;
}
ChatGPT 님의 말씀 →
1. .data.rel.ro.local 섹션의 역할
.data.rel.ro.local 섹션은 읽기 전용 데이터의 위치 독립적인 주소를 관리하기 위해 사용됩니다. 이는 주로 다음 경우에 생성됩니다:
vector, priority_queue 등의 동적 컨테이너는 위치 독립적인 실행 파일(PIE)을 위해 이 섹션에 메타데이터를 저장할 수 있습니다.vector 및 fill 초기화를 수행하는 방식이 이 섹션을 생성하도록 유도할 수 있습니다.C++17 표준 라이브러리를 처리하는 과정에서 .data.rel.ro.local 섹션을 생성할 수 있습니다.2. 첫 번째 코드에서 문제가 발생하지 않는 이유
.data.rel.ro.local 섹션을 생성할 필요가 없습니다.3. 두 번째 코드에서 문제가 발생하는 이유
vector<pii>와 같은 동적 컨테이너를 사용.priority_queue를 사용하여 정렬 및 관리..data.rel.ro.local 섹션을 포함한 어셈블리 코드를 생성하게 만듭니다. 그러나 macOS의 기본 어셈블러(Clang)는 이 섹션을 처리하지 못합니다.요약하자면, 벡터처럼 동적으로 생성하는 코드가 에러를 발생한 거였고, 맥 기본 어셈블러는 처리하지 못한다는 것이였다.
macOS의 기본 어셈블러를 GNU 어셈블러로 변경
brew install binutils
설치 후, GNU as(어셈블러)를 기본으로 사용하도록 설정
export PATH="/usr/local/opt/binutils/bin:$PATH"
macOS에서 GCC 대신 Clang을 사용
clang++ -std=c++17 real-test.cpp -o real-test
먼저 커맨드창으로 컴파일하고 실행해봤더니 되는 것 확인.

그러나 나는 code runner로, cmd + R 을 누르면 컴파일부터 실행이 되게끔 설정했었다.
cd "/(폴더 위치)/" && g++ -std=c++17 real-test.cpp -o real-test && "/(폴더 위치)/"real-test
다른점은 g++이 아니라 clang++로 실행하게 하면 된다.
vsc 설정에서 Code runner Executor Map 을 찾은 후, Edit in settings.json 클릭

cpp에서 && g++ → && clang++로 바꾸면 됨.
...,
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"zig": "zig run",
"cpp": "cd $dir && **clang++** -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
...
정상작동 확인!
