ALGORITHM ๐Ÿค–

์•Œ๊ณ ๋ฆฌ์ฆ˜ ์—ฐ์Šต / ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ค€๋น„
[Silver III] ๋“ฑ์ˆ˜ ๋งค๊ธฐ๊ธฐ - 2012 ๋ฌธ์ œ ๋งํฌ ์„ฑ๋Šฅ ์š”์•ฝ ๋ฉ”๋ชจ๋ฆฌ: 311344 KB, ์‹œ๊ฐ„: 1864 ms ๋ถ„๋ฅ˜ ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜, ์ •๋ ฌ ๋ฌธ์ œ ์„ค๋ช… 2007๋…„ KOI์— N๋ช…์˜ ํ•™์ƒ๋“ค์ด ์ฐธ๊ฐ€ํ•˜์˜€๋‹ค. ๊ฒฝ์‹œ์ผ ์ „๋‚ ์ธ ์˜ˆ๋น„์†Œ์ง‘์ผ์—, ๋ชจ๋“  ํ•™์ƒ๋“ค์€ ์ž์‹ ์ด N๋ช… ์ค‘์—์„œ ๋ช‡ ๋“ฑ์„ ํ•  ๊ฒƒ์ธ์ง€ ์˜ˆ์ƒ ๋“ฑ์ˆ˜๋ฅผ ์ ์–ด์„œ ์ œ์ถœํ•˜๋„๋ก ํ•˜์˜€๋‹ค. KOI ๋‹ด๋‹น์กฐ๊ต๋กœ ์ฐธ๊ฐ€ํ•œ ๊น€์ง„์˜ ์กฐ๊ต๋Š” ์‹ค์ˆ˜๋กœ ๋ชจ๋“  ํ•™์ƒ์˜ ํ”„๋กœ๊ทธ๋žจ์„ ๋‚ ๋ ค ๋ฒ„๋ ธ๋‹ค. 1๋“ฑ๋ถ€ํ„ฐ N๋“ฑ๊นŒ์ง€ ๋™์„์ฐจ ์—†์ด ๋“ฑ์ˆ˜๋ฅผ ๋งค๊ฒจ์•ผ ํ•˜๋Š” ๊น€ ์กฐ๊ต๋Š”, ์–ด์ฉ” ์ˆ˜ ์—†์ด ๊ฐ ์‚ฌ๋žŒ์ด ์ œ์ถœํ•œ ์˜ˆ์ƒ ๋“ฑ์ˆ˜๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ž„์˜๋กœ ๋“ฑ์ˆ˜๋ฅผ ๋งค๊ธฐ๊ธฐ๋กœ ํ–ˆ๋‹ค. ์ž์‹ ์˜ ๋“ฑ์ˆ˜๋ฅผ A๋“ฑ์œผ๋กœ ์˜ˆ์ƒํ•˜์˜€๋Š”๋ฐ ์‹ค์ œ ๋“ฑ์ˆ˜๊ฐ€ B๋“ฑ์ด ๋  ๊ฒฝ์šฐ, ์ด ์‚ฌ๋žŒ์˜ ๋ถˆ๋งŒ๋„๋Š” A์™€ B์˜ ์ฐจ์ด (|A - B|)๋กœ ์ˆ˜์น˜ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹น์‹ ์€ N๋ช…..
https://school.programmers.co.kr/learn/courses/30/lessons/160586 import java.util.*; class Solution { public int[] solution(String[] keymap, String[] targets) { int[] answer = new int[targets.length]; Map pressCount = new HashMap(); // key: ๋ฌธ์ž, value: ์ตœ์†Œ ์ž…๋ ฅ ํšŸ์ˆ˜ for (String key : keymap) { // ๊ฐ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ํ‚ค๋ฅผ ๋ˆ„๋ฅด๋Š” ์ตœ์†Œ ํšŸ์ˆ˜๋ฅผ ๋งต์— ์ €์žฅ for (int i = 0; i < key.length(); i++) { char ch = key.charAt(i); if (!p..
https://www.acmicpc.net/problem/2012 2012๋ฒˆ: ๋“ฑ์ˆ˜ ๋งค๊ธฐ๊ธฐ ์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 500,000) ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ๊ฐ ์‚ฌ๋žŒ์˜ ์˜ˆ์ƒ ๋“ฑ์ˆ˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. ์˜ˆ์ƒ ๋“ฑ์ˆ˜๋Š” 500,000 ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] expectRank = new int[n]; // ์˜ˆ์ƒ ๋“ฑ์ˆ˜๋ฅผ ๋‹ด์„ ๋ฐฐ์—ด long disSat = 0; // ์ตœ์†Œ ๋ถˆ๋งŒ๋„์˜ ํ•ฉ for (int i..
https://www.acmicpc.net/problem/1543 1543๋ฒˆ: ๋ฌธ์„œ ๊ฒ€์ƒ‰ ์„ธ์ค€์ด๋Š” ์˜์–ด๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ์–ด๋–ค ๋ฌธ์„œ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค๋ ค๊ณ  ํ•œ๋‹ค. ์ด ํ•จ์ˆ˜๋Š” ์–ด๋–ค ๋‹จ์–ด๊ฐ€ ์ด ๋ช‡ ๋ฒˆ ๋“ฑ์žฅํ•˜๋Š”์ง€ ์„ธ๋ ค๊ณ  ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, ์„ธ์ค€์ด์˜ ํ•จ์ˆ˜๋Š” ์ค‘๋ณต๋˜์–ด ์„ธ๋Š” ๊ฒƒ์€ ๋นผ๊ณ  ์„ธ์•ผ ํ•œ www.acmicpc.net import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String document = sc.nextLine(); String search = sc.nextLine(); int count = 0; // ์ค‘๋ณต๋˜์ง€ ์•Š๊ณ  ๊ฒ€์ƒ‰ํ•˜๊ณ  ์‹ถ์€ ๋‹จ์–ด๊ฐ€ ๋“ฑ์žฅํ•  ์ˆ˜ ..
https://www.acmicpc.net/problem/2667 2667๋ฒˆ: ๋‹จ์ง€๋ฒˆํ˜ธ๋ถ™์ด๊ธฐ ๊ณผ ๊ฐ™์ด ์ •์‚ฌ๊ฐํ˜• ๋ชจ์–‘์˜ ์ง€๋„๊ฐ€ ์žˆ๋‹ค. 1์€ ์ง‘์ด ์žˆ๋Š” ๊ณณ์„, 0์€ ์ง‘์ด ์—†๋Š” ๊ณณ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ฒ ์ˆ˜๋Š” ์ด ์ง€๋„๋ฅผ ๊ฐ€์ง€๊ณ  ์—ฐ๊ฒฐ๋œ ์ง‘์˜ ๋ชจ์ž„์ธ ๋‹จ์ง€๋ฅผ ์ •์˜ํ•˜๊ณ , ๋‹จ์ง€์— ๋ฒˆํ˜ธ๋ฅผ ๋ถ™์ด๋ ค ํ•œ๋‹ค. ์—ฌ www.acmicpc.net import java.util.*; import java.io.*; public class Main { static int[][] arr; static boolean[][] visited; static int N, count; static ArrayList result; static int[] dx = {-1, 1, 0, 0}; static int[] dy = {0, 0, -1, 1}; public..
https://www.acmicpc.net/problem/2468 2468๋ฒˆ: ์•ˆ์ „ ์˜์—ญ ์žฌ๋‚œ๋ฐฉ์žฌ์ฒญ์—์„œ๋Š” ๋งŽ์€ ๋น„๊ฐ€ ๋‚ด๋ฆฌ๋Š” ์žฅ๋งˆ์ฒ ์— ๋Œ€๋น„ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ผ์„ ๊ณ„ํšํ•˜๊ณ  ์žˆ๋‹ค. ๋จผ์ € ์–ด๋–ค ์ง€์—ญ์˜ ๋†’์ด ์ •๋ณด๋ฅผ ํŒŒ์•…ํ•œ๋‹ค. ๊ทธ ๋‹ค์Œ์— ๊ทธ ์ง€์—ญ์— ๋งŽ์€ ๋น„๊ฐ€ ๋‚ด๋ ธ์„ ๋•Œ ๋ฌผ์— ์ž ๊ธฐ์ง€ ์•Š๋Š” www.acmicpc.net import java.util.*; import java.io.*; public class Main { static int[][] arr; static boolean[][] visited; static int N; static int[] dx = {-1, 1, 0, 0}; static int[] dy = {0, 0, -1, 1}; static int[] result; public static void m..
https://school.programmers.co.kr/learn/courses/30/lessons/42586 import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { int[] day = new int[progresses.length]; Queue queue = new LinkedList(); List answer = new ArrayList(); for (int i = 0; i < progresses.length; i++) { int temp = progresses[i]; while (temp < 100) { temp += speeds[i]; day[i] += 1; } queue.add(d..
daxx0ne
'ALGORITHM ๐Ÿค–' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (3 Page)