[BOJ] 1012: 유기농 배추 / JS
2022. 10. 7. 21:29
알고리즘
문제: https://www.acmicpc.net/problem/1012 const [t, ...input] = require('fs') .readFileSync('./input.txt') .toString() .trim() .split('\n'); let n, m; const dx = [0, 0, 1, -1]; const dy = [1, -1, 0, 0]; function isRange(x, y) { return x >= 0 && x = 0 && y < m; } function bfs(i, j) { const queue = [[i, j]]; map[i][j] = 0; while (queue.length) { const [x, y] = queue.shift(); for (let i = ..
[BOJ] 2178: 미로 탐색 / JS
2022. 10. 7. 03:02
알고리즘
문제: https://www.acmicpc.net/problem/2178 const [nm, ...input] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n'); const [n, m] = nm.split(' ').map(Number); const maze = input.map((s) => s.trim().split('').map(Number)); const visit = new Array(n); for (let i = 0; i 0); const dx = [0, 0, -1, 1]; const dy = [1, -1, 0, 0]; fu..
[BOJ] 1926: 그림 / JS
2022. 10. 7. 02:20
알고리즘
문제: https://www.acmicpc.net/problem/1926 const [nm, ...input] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n'); const [n, m] = nm.split(' ').map(Number); const picture = input.map((s) => s.split(' ').map(Number)); function isRange(x, y) { return x >= 0 && x = 0 && y < m; } const dx = [0, 1, 0, -1]; const dy = [1, 0, -1, 0]; function bfs(i, j) { let area = 0; pic..
[BOJ] 11003: 최솟값 찾기
2022. 10. 3. 02:24
알고리즘
문제: https://www.acmicpc.net/problem/11003 #include using namespace std; deque dq; int n, l, num; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> l; for (int i = 0; i > num; if (!dq.empty() && dq.front().second + l == i) dq.pop_front(); while (!dq.empty() && dq.back().first >= num) dq.pop_back(); dq.push_back({num, i}); cout 최솟값을 덱에 저장하기 위함이며 큰 값들은 이미 최솟값의 의미를 잃었기 때..
[BOJ] 2493: 탑
2022. 10. 2. 19:33
알고리즘
문제: https://www.acmicpc.net/problem/2493 : 처음 작성한 코드 #include using namespace std; stack tower; vector result; int n, k; int pos, max_k; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > k; if (!tower.empty()) { if (tower.top() > k) pos = tower.size(); else { if (k > max_k) { max_k = k; pos = 0; } } } tower.push(k); result.push_back(pos); } for (int..
[BOJ] 2504: 괄호의 값
2022. 10. 1. 22:45
알고리즘
문제: https://www.acmicpc.net/problem/2504 #include using namespace std; string str; stack st; int result, num = 1, valid = 1; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> str; for (int i = 0; i < str.length(); i++) { if (str[i] == '(') { num *= 2; st.push(str[i]); } else if (str[i] == '[') { num *= 3; st.push(str[i]); } else if (str[i] == ')') { if (st.empty() || st.top() != '(') { cout
[BOJ] 10799: 쇠막대기
2022. 10. 1. 20:02
알고리즘
문제: https://www.acmicpc.net/problem/10799 #include using namespace std; string str; stack st; int result; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> str; for (int i = 0; i < str.length(); i++) { if (str[i] == '(') st.push('('); else { st.pop(); if (str[i - 1] == '(') result += st.size(); else result++; } } cout 가장 오른쪽에 있는 조각
[BOJ] 3986: 좋은 단어
2022. 10. 1. 18:29
알고리즘
문제: https://www.acmicpc.net/problem/3986 #include using namespace std; int n, result; string ab; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > ab; for (char c : ab) { if (!word.empty() && word.top() == c) word.pop(); else word.push(c); } if (word.empty()) result++; } cout
[BOJ] 5430: AC
2022. 10. 1. 17:36
알고리즘
문제: https://www.acmicpc.net/problem/5430 #include using namespace std; void parse(string& arr, deque& dq) { int num = 0; for (int i = 1; i + 1 = '0' && arr[i] n >> arr; parse(arr, dq); for (char f : p) { if (f == 'R') rev = 1 - rev; else { if (dq.empty()) { error = 1; break; } if (rev) dq.pop_back(); else dq.pop_front(); } } if (error) c..