ํˆฌํฌ์ธํ„ฐ, ํšŒ๋ฌธ ํŒ๋ณ„

Solution rust soulution Memo ํˆฌํฌ์ธํ„ฐ ํŒฐ๋ฆฐ๋“œ๋กฌ ํŒ๋ณ„ ๋ฌธ์ œ ๋™์ผํ•œ ๋กœ์ง์˜ ํŒฐ๋ฆฐ๋“œ๋กฌ์„ ๋‘๋ฒˆ ๊ตฌํ˜„ํ•ด์„œ ํ•œ ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•˜๋„๋ก ์ˆ˜์ •ํ•œ๋‹ค. // Baekjoon - 17609 // https://www.acmicpc.net/problem/17609 use std::io::{self, Read, Write}; fn main() { let mut stdin = io::stdin().lock(); let mut stdout = io::stdout().lock(); let mut input = String::new(); stdin.read_to_string(&mut input).unwrap(); let mut lines = input.lines(); let n: usize = lines.next().unwrap().parse().unwrap(); for _ in 0..n { let tmp = lines.next().unwrap(); let result = is_palindrome(tmp); writeln!...

May 13, 2025

ํˆฌํฌ์ธํ„ฐ 1

Solution rust soulution Memo ํˆฌํฌ์ธํ„ฐ ๊ธฐ๋ณธ // Baekjoon - 2003 // https://www.acmicpc.net/problem/2003 use std::io::{self, Read, Write}; fn main() { let mut stdin = io::stdin().lock(); let mut stdout = io::stdout().lock(); let mut input = String::new(); stdin.read_to_string(&mut input).unwrap(); let mut lines = input.lines(); let meta_line: Vec<usize> = lines.next().unwrap() .split_whitespace() .map(|x| x.parse().unwrap()) .collect(); let n = meta_line[0]; let m = meta_line[1]; let nums: Vec<usize> = lines.next().unwrap() .split_whitespace() .map(|x| x.parse().unwrap()) .collect(); let mut count = 0; let mut sum = 0; let mut left = 0; for right in 0....

May 12, 2025

ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ ์„œ์น˜ 3

Solution rust soulution Memo ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ์„œ์น˜ ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ ์„œ์น˜๋กœ โ€˜๋ถ„๋ฅ˜โ€™๋˜๋Š” ๋ฌธ์ œ์ธ๊ฑธ ์•Œ์•„์„œ ๊ฒจ์šฐ ํ‘ผ ๊ฒƒ ๊ฐ™๋‹ค. ์ด๋Ÿฐ ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์„๊นŒ ์‹ถ์œผ๋ฉด์„œ๋„ ๋ญ”๊ฐ€ ์กฐ๊ธˆ ๋” ์ตœ์ ํ™”๋œ ๋ธŒ๋ฃจํŠธํฌ์Šค ํ’€์ด๋ฅผ ์ƒ๊ฐํ•˜๋ฉด ์ข‹์€ ๊ฒƒ ๊ฐ™๋‹ค ๋ธŒ๋ฃจํŠธํฌ์Šค > dp > ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ ์ด์ˆœ์„œ๋กœ ๊ฐ€๋Šฅ? ํ•˜๋ฉด์„œ ์ƒ๊ฐํ•ด๋ณด๋ฉด ์ข‹์„๊ฒƒ๊ฐ™๋‹ค. can_split ํ•จ์ˆ˜๋Š” ๊ทธ๋ฆฌ๋””๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค. ์ƒˆ๋กœ์šด ์›์†Œ๋งˆ๋‹ค ์ตœ๋Œ€๊ฐ’ ์ตœ์†Œ๊ฐ’์„ ๊ฐฑ์‹ ํ•ด์„œ ๋งŒ์•ฝ ์ง€๊ธˆ ์ƒํƒœ์˜ ๋ฐฐ์—ด์ด ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ์œผ๋กœ ์„ ์ •๋œ ์ตœ๋Œ€๊ฐ’๋ณด๋‹ค ์ž‘๋‹ค๋ฉด ์›์†Œ๋ฅผ ๋” ์ถ”๊ฐ€ํ•˜๊ณ  ํฌ๋‹ค๋ฉด ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•œ๋‹ค. ๊ฒฐ๊ตญ ๋ฐฐ์—ด์„ ์ „๋ถ€ ๋งŒ๋“ค์—ˆ์„๋•Œ, ์กฐ๊ฑด์„ ๋‹ฌ์„ฑํ–ˆ๋Š”์ง€ ํŒ๋ณ„ํ•œ๋‹ค....

May 12, 2025

ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ ์„œ์น˜2

Solution rust soulution Memo ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ์„œ์น˜ 2 ์—†์œผ๋ฉด ๋ญ”๊ฐ€ ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ์„๊นŒ ์‹ถ์€๋ฐ ์ž˜ ๋– ์˜ค๋ฅด์ง€๋Š” ์•Š๋Š”๋‹ค. // Baekjoon - 2110 // https://www.acmicpc.net/problem/2110 use std::io::{self, Read, Write}; fn main() { let mut stdin = io::stdin().lock(); let mut stdout = io::stdout().lock(); let mut input = String::new(); stdin.read_to_string(&mut input).unwrap(); let mut lines = input.lines(); let first_line = lines.next().unwrap(); let parts: Vec<u64> = first_line .split_whitespace() .map(|x| x.parse().unwrap()) .collect(); let n = parts[0]; let c = parts[1]; let mut houses: Vec<u64> = vec!...

May 9, 2025

ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ ์„œ์น˜

Solution rust soulution Memo ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ์„œ์น˜ ์ด๊ฑด ์ฒ˜์Œ ๋ณด๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ์ด๋ถ„ํƒ์ƒ‰์˜ ์‘์šฉ t/f ํ‰๊ฐ€๊ฐ’์ค‘ ๋งˆ์ง€๋ง‰ t์˜ ํ‰๊ฐ€๊ฐ’์„ ์ฐพ๋Š”๋‹ค. ์ƒํ™ฉ ์ž์ฒด๋ฅผ ์ผ์ข…์˜ ์ •๋ ฌ๋œ ๋ฐฐ์—ด๋กœ ๋ณด๋ฉด ํŽธํ•˜๋‹ค๊ณ  ํ•œ๋‹ค. https://gliver.tistory.com/31 // Baekjoon - 2805 // https://www.acmicpc.net/problem/2805 use std::io::{self, Read, Write}; fn main() { let mut stdin = io::stdin().lock(); let mut stdout = io::stdout().lock(); let mut input = String::new(); stdin.read_to_string(&mut input).unwrap(); let mut lines = input.lines(); let first_line = lines.next().unwrap(); let parts: Vec<u64> = first_line ....

May 9, 2025

๊ธฐ๋ณธ ์ด๋ถ„ํƒ์ƒ‰ ๋ฌธ์ œ! 2

Solution rust soulution Memo ์ด๋ถ„ํƒ์ƒ‰ ๋ฌธ์ œ ๋ญ”๊ฐ€ ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ๋ถ„๋ฅ˜๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ๋‹ค๋ฅธ๊ฑธ๋กœ ํ’€์—ˆ์„์ง€๋„ ์ •๋ ฌ ํ›„, ๋‚˜๋Š” ๋†’์ด์˜ ์ธ๋ฑ์Šค๊ฐ€ ๋ถ€๋”ชํžˆ์ง€ ์•Š๋Š” ๋ฒฝ์˜ ์ˆซ์ž๊ฐ€ ๋œ๋‹ค. (๊ทธ๊ฑธ ๊ธธ์ด์—์„œ ๋นผ์คŒ) // Baekjoon - 3020 // https://www.acmicpc.net/problem/3020 use std::io::{self, Read, Write}; fn main() { let mut stdin = io::stdin().lock(); let mut stdout = io::stdout().lock(); let mut input = String::new(); stdin.read_to_string(&mut input).unwrap(); let mut lines = input.lines(); let first_line = lines.next().unwrap(); let parts: Vec<usize> = first_line .split_whitespace() ....

May 9, 2025

๊ธฐ๋ณธ ์ด๋ถ„ํƒ์ƒ‰ ๋ฌธ์ œ!

Solution rust soulution Memo ๋ฐ”์ด๋„ˆ๋ฆฌ์„œ์น˜๋กœ ๋‚จ๊ฒจ์ง„ ๋ฌธ์ œ์ธ๋ฐ ๋ฐ”์ด๋„ˆ๋ฆฌ์„œ์น˜๋Š” ์‹คํŒจํ–ˆ๋‹ค. ์ž…์ถœ๋ ฅ์ตœ์ ํ™”๋ฅผ ๋งˆ์ง€๋ง‰์—ํ•ด์„œ ๋ญ๊ฐ€ ์›์ธ์ธ์ง€๋Š” ๋ชป๋ฐํ˜”๋‹ค. ๊ทธ๋ž˜์„œ ๊ทธ๋ƒฅ ๋ฐ”์ด๋„ˆ๋ฆฌ์„œ์น˜๋Š” ๊ตฌํ˜„ํ•ด๋‘  // Baekjoon - 1920 // https://www.acmicpc.net/problem/1920 use std::collections::HashSet; use std::io::{self, BufRead, Write}; fn main() { let stdin = io::stdin(); let stdout = io::stdout(); let mut stdin = stdin.lock(); let mut stdout = stdout.lock(); let mut line = String::new(); stdin.read_line(&mut line).unwrap(); line.clear(); stdin.read_line(&mut line).unwrap(); let nums: HashSet<i32> = line.split_whitespace() .map(|x| x.parse().unwrap()) .collect(); line.clear(); stdin....

May 7, 2025

dp? ๋ฐฑํŠธ๋ž˜ํ‚น?

Solution rust soulution Memo ๋ฆฟ์ฝ”๋“œ dp๋ฌธ์ œ ๊ทผ๋ฐ ์™œ ์ด๊ฒŒ dp์ง€.. // LeetCode - generate-parentheses // https://leetcode.com/problems/generate-parentheses/description/?envType=problem-list-v2&envId=dynamic-programming /** Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2: Input: n = 1 Output: ["()"] */ struct Solution; impl Solution { fn new() -> Self { Solution } pub fn generate_parenthesis(n: i32) -> Vec<String> { let mut result = Vec::new(); let mut current = String::new(); Self::backtrack(&mut result, &mut current, 0, 0, n as usize); result } fn backtrack(result: &mut Vec<String>, current: &mut String, open: usize, close: usize, max: usize) { if current....

May 7, 2025

๋ฐฑํŠธ๋ž˜ํ‚น์„ ์ด์šฉํ•œ ์Šค๋„์ฟ  ์†”๋ฒ„

Solution rust soulution Memo ๊ตฌํ˜„์ด ๊ท€์ฐฎ์€ ๊ฒƒ ๋นผ๋ฉด ๊ทธ๋ƒฅ ํ‰์ดํ•œ ๋ฐฑํŠธ๋ž˜ํ‚น ํƒ€๊ฒŸ(๋นˆ์นธ)์„ ๋”ฐ๋กœ ์ถ”์ถœํ•œ๋‹ค. ํšก, ์ข…, ์ค‘์•™๊ฐ’ ๊ธฐ์ค€์œผ๋กœ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š” ์ˆซ์ž ํ›„๋ณด๋ฅผ ์ถ”์ถœํ•œ๋‹ค. ํƒ€๊ฒŸ ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค ๊ธฐ์ค€์œผ๋กœ ํ›„๋ณด์ˆซ์ž๋ฅผ ์ „๋ถ€ ๋„ฃ์–ด๋ณด๋ฉฐ ๋ฐฑํŠธ๋ž˜ํ‚น // Baekjoon - 2580 // https://www.acmicpc.net/problem/2580 use std::io::{self, Read, Write}; const MAX_LEN: usize = 9; fn main() { let mut stdin = io::stdin().lock(); let mut stdout = io::stdout().lock(); let mut input = String::new(); stdin.read_to_string(&mut input).unwrap(); let mut lines = input....

May 6, 2025

์˜ค๋Š˜ ๊ฐ€์žฅ ์–ด๋ ค์› ๋˜ dp๋ฌธ์ œ

Solution rust soulution Memo ๊ฐ๊ฐ์˜ ์›์†Œ์— ๋Œ€ํ•œ i ๊นŒ์ง€์˜ lis, i๋ถ€ํ„ฐ์˜ lds๋ฅผ ๊ตฌํ•ด์„œ ๊ฐ๊ฐ์˜ dp๋ฐฐ์—ด์— ์ €์žฅํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์š”๊ตฌ๋ฐ›์€ ์ธ๋ฑ์Šค์— ๋Œ€ํ•ด์„œ lis + lds - 1์„ ๋ฆฌํ„ด ์ผ๋‹จ ์œ„์˜ ์•„์ด๋””์–ด๋ฅผ ๋ชป๋– ์šธ๋ ค์„œ ์—„์ฒญ ํ•ด๋งธ๊ณ , ๊ตฌํ˜„๋„ ์—ญ์ˆœ์˜ ์ธ๋ฑ์Šค๊ฐ€ ๋„ˆ๋ฌด ํ—ท๊ฐˆ๋ ค์„œ ๋งŽ์ด ํ•ด๋งธ๋‹ค. // Baekjoon - 11054 // https://www.acmicpc.net/problem/11054 use std::cmp::max; use std::io::{self, Read, Write}; fn main() { let mut stdin = io::stdin().lock(); let mut stdout = io::stdout().lock(); let mut input = String::new(); stdin.read_to_string(&mut input)....

May 6, 2025