BOJ1261_์•Œ๊ณ ์ŠคํŒŸ
Coding Test 2022. 9. 23. 14:29

๋ฌธ์ž์—ด๋กœ ๋ฐ›์•˜์œผ๋‹ˆ ์•„์Šคํ‚ค์ฝ”๋“œ 48๋งŒํผ ๋นผ์ฃผ๋Š” ๊ฑฐ ์žŠ์ง€ ๋ง๊ธฐ #include #include #include #include #define INF (int(1e9)) using namespace std; struct Edge { int pos[2]; int cost; }; struct cmp { bool operator() (Edge a, Edge b) { if (a.cost d[cur.pos[0]][cur.pos[1]]) continue; for(int i = 0; i = N || nc >= M) continue; if (d[nr][nc] > M >> N; mem..

BOJ11779_์ตœ์†Œ๋น„์šฉ ๊ตฌํ•˜๊ธฐ2
Coding Test 2022. 9. 22. 21:52

๊ฒฝ๋กœ ์ €์žฅ๋ฐฉ์‹ ์ฃผ์˜! ๋‹ค์ต์ŠคํŠธ๋ผ ์ง„ํ–‰ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฐ์—ด๊ณผ ์ตœ์ข… ๋ฃจํŠธ๋ฅผ ์ €์žฅํ•  ๋ฐฐ์—ด ์ถ”๊ฐ€ if (d[next.to] = b.cost) return false; else return true; } }; int n, m; vector graph[1005]; // ๋ฒ„์Šค ์ •๋ณด vector t_route; int route[1005]; int d[1005]; // ์ถœ๋ฐœ ์ง€์ ์—์„œ ๊ฐ ์ง€์ ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ void dijkstra(int s) { priority_queue pq; pq.push({s, 0}); d[s] = 0; int i = 0; while(!pq.empty()) { Edge cur = pq.top(); pq.pop(); // cout m; int s, e, c; for (int i = 0; i < m ;..

BOJ4485_๋…น์ƒ‰ ์˜ท ์ž…์€ ์• ๊ฐ€ ์ ค๋‹ค์ง€? (C++)
Coding Test 2022. 9. 22. 17:32

BFS + ๋‹ค์ต์ŠคํŠธ๋ผ cmp ๋ถ€ํ˜ธ ์ฃผ์˜ #include #include #include #define INF int(1e9) using namespace std; struct Edge{ int pos[2]; int cost; }; struct cmp { bool operator() (Edge a, Edge b) { if (a.cost d[cur.pos[0]][cur.pos[1]]) continue; for(int i = 0; i = N || nc >= N) continue; if (d[nr][nc] > N; while (N != 0..

BOJ1504_ํŠน์ •ํ•œ ์ตœ๋‹จ ๊ฒฝ๋กœ
Coding Test 2022. 9. 22. 13:19

// if (res >= INF || res > n >> e; int a, b, c; for (int i = 0; i < e; i++) { c..

BOJ1238_ํŒŒํ‹ฐ (C++)
Coding Test 2022. 9. 21. 16:00

#include #include #include #include #define INF int(1e9) using namespace std; struct Edge { int to; int cost; }; struct cmp { bool operator() (Edge a, Edge b) { if (a.cost n >> m >> x; // ์ •์  ๊ฐฏ์ˆ˜, ๊ฐ„์„  ๊ฐฏ์ˆ˜, ๋„์ฐฉ์ง€์  int s, e, t; for (int i = 0; i > s >> e >> t; graph[s].push_back({e, t}); // to, cost } memset(total_d, 0, sizeof(total_d)); for (int i = 1; i

BOJ13549_์ˆจ๋ฐ”๊ผญ์งˆ3
Coding Test 2022. 9. 21. 15:58

๋‹ค์ต์ŠคํŠธ๋ผ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ๋ฌด์กฐ๊ฑด ์ด์ค‘ vector ๋„ฃ์„ ํ•„์š” ์—†์Œ. ์ด ๋ฌธ์ œ์˜ ๊ฒฝ์šฐ graph์— ๊ฐ๊ฐ 3๊ฐœ์˜ ๊ฐ„์„  ๋„ฃ์—ˆ๋”๋‹ˆ runtime error graph ๋Œ€์‹  ์กฐ๊ฑด๋ฌธ์œผ๋กœ ๋ฐ”๊ฟจ๋”๋‹ˆ ๋ฉ”๋ชจ๋ฆฌ ์ดˆ๊ณผ ์•ˆ๋‚จ ์ดํ›„ ๋˜ ํ‹€๋ ธ๋Š”๋ฐ if(b > k * 2) ๋ผ๋Š” ์ด์ƒํ•œ ์กฐ๊ฑด๋ฌธ ๋„ฃ์–ด์„œ ํ‹€๋ฆผ // graph ์— ๊ฐ๊ฐ 3๊ฐœ์˜ ๊ฐ„์„  ๋„ฃ์œผ๋ฉด runtime error // graph ๋Œ€์‹  ์กฐ๊ฑด๋ฌธ์œผ๋กœ bad alloc ์—†์•ฐ // if(b > k * 2) ๋ผ๋Š” ์ด์ƒํ•œ ์กฐ๊ฑด๋ฌธ ๋„ฃ์–ด์„œ ํ‹€๋ฆผ #include #include #include #define INF int(1e5) using namespace std; struct Edge { int to; int cost; }; struct cmp { bool operator() (Edge a..