diff --git "a/BOJ/1000-5000\353\262\210/JY_1911.java" "b/BOJ/1000-5000\353\262\210/JY_1911.java" new file mode 100644 index 00000000..7b11d13e --- /dev/null +++ "b/BOJ/1000-5000\353\262\210/JY_1911.java" @@ -0,0 +1,72 @@ +package day1029; + +import java.io.*; +import java.util.*; + +public class JY_1911 { + + static int N, L; + static long[][] hrr; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + L = Integer.parseInt(st.nextToken()); + + hrr = new long[N][2]; + for(int i=0; iLong.compare(o1[0], o2[0])); + + long s = 0; + long e = hrr[N-1][1]; // 최대의 널빤지수 == L이 1이고, 가장 마지막 물웅덩이까지 다 덮을 때 + long cnt = 0; + + while(s <= e) { + long mid = (s + e) / 2; + + if(isPossible(mid)) { + cnt = mid; + e = mid - 1; + }else { + s = mid + 1; + } + } + + System.out.println(cnt); + + } + public static boolean isPossible(long mid) { + long pre = 0; // 마지막 널빤지 위치 + long total = 0; // 총 필요한 널빤지 개수 + for(int i=0; i mid) return false; + + pre = pre + cnt * L; // 마지막 널빤지 위치 갱신 + } + + return true; + } + +} diff --git "a/BOJ/1000-5000\353\262\210/JY_2461.java" "b/BOJ/1000-5000\353\262\210/JY_2461.java" new file mode 100644 index 00000000..8ce2960c --- /dev/null +++ "b/BOJ/1000-5000\353\262\210/JY_2461.java" @@ -0,0 +1,60 @@ +package day1031; + +import java.io.*; +import java.util.*; + +public class JY_2461 { + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + + int[][] srr = new int[N][M]; + for(int i=0; i srr[i][j]) { + min = srr[i][j]; + minIdx = i; + } + } + + ans = Math.min(ans, max-min); + n[minIdx]++; + if(n[minIdx] == M) break; + + } + + System.out.println(ans); + + } + + +} diff --git "a/BOJ/20001-25000\353\262\210/JY_20007.java" "b/BOJ/20001-25000\353\262\210/JY_20007.java" new file mode 100644 index 00000000..37512909 --- /dev/null +++ "b/BOJ/20001-25000\353\262\210/JY_20007.java" @@ -0,0 +1,125 @@ +package day1030; + +import java.io.*; +import java.util.*; + +public class JY_20007 { + + static long INF = Long.MAX_VALUE; + static int N, M, X, Y; + static List[] g; + static long[] distance; + static class Node implements Comparable { + int n; + long dist; + + public Node(int n, long dist) { + super(); + this.n = n; + this.dist = dist; + } + @Override + public int compareTo(Node other) { + return Long.compare(this.dist, other.dist); + } + + @Override + public String toString() { + return "Node [n=" + n + ", dist=" + dist + "]"; + } + + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + X = Integer.parseInt(st.nextToken()); + Y = Integer.parseInt(st.nextToken()); + + g = new ArrayList[N]; + for(int i=0; i(); + } + + distance = new long[N]; + for(int i=0; i=0; i--) { + if(2*distance[i] > X) { + System.out.println(-1); + return; + } + } + + // 투포인터 이거 왜안되죠??? + // X= 21, distance = [0, 1, 1, 9, 9]이면 최소일수는 2일아닌가요??!! ㅠ0ㅠ +// int s = 0; +// int e = N-1; +// long sum = 2*distance[e]; +// while(s <= e) { +// if(sum + 2*distance[s] <= X) { +// sum += 2*distance[s]; +// s++; +// } else { +// e--; +// ans++; +// sum = 2*distance[e]; +// } +// } + + int ans = 1; + long sum = 0; + for(int i=0; i X) { + ans++; + sum = 2*distance[i]; + } else { + sum += 2*distance[i]; + } + } + + System.out.println(ans); + + } + public static void dijkstra(int start) { + distance[start] = 0; + PriorityQueue pq = new PriorityQueue<>(); + pq.add(new Node(start, 0)); + + while(!pq.isEmpty()) { + Node now = pq.poll(); + + if(distance[now.n] < now.dist) continue; + + for(Node next: g[now.n]) { + long cost = now.dist + next.dist; + if(distance[next.n] > cost) { + distance[next.n] = cost; + pq.add(new Node(next.n, cost)); + } + } + } + } + +} diff --git "a/BOJ/5001-10000\353\262\210/JY_9342.java" "b/BOJ/5001-10000\353\262\210/JY_9342.java" new file mode 100644 index 00000000..c6d1cbac --- /dev/null +++ "b/BOJ/5001-10000\353\262\210/JY_9342.java" @@ -0,0 +1,72 @@ +package day1029; + +import java.io.*; +import java.util.*; + +public class JY_9342 { + + static boolean isOk; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(br.readLine()); + for(int t=0; t> 규칙 + * 0 : 문자열은 {A, B, C, D, E, F} 중 0개 또는 1개로 시작해야 한다. + * 1 : 그 다음에는 A가 하나 또는 그 이상 있어야 한다. + * 2 : 그 다음에는 F가 하나 또는 그 이상 있어야 한다. + * 3 : 그 다음에는 C가 하나 또는 그 이상 있어야 한다. + * 4 : 그 다음에는 {A, B, C, D, E, F} 중 0개 또는 1개가 있으며, 더 이상의 문자는 없어야 한다. + * */ + public static void isGen(String s, int idx, int type) { + if(type == 0) { + if(s.charAt(idx) >= 'A' && s.charAt(idx) <= 'F') { + if(s.charAt(idx) == 'A') isGen(s, idx, 1); // 다음 조건도 A로 시작하므로 인덱스 증가X + else isGen(s, idx+1, 1); + } + } else if(type == 1) { + int next = check(s, idx, 'A'); + if(next != -1) { + isGen(s, next, 2); + } + } else if(type == 2) { + int next = check(s, idx, 'F'); + if(next != -1) { + isGen(s, next, 3); + } + } else if(type == 3) { + int next = check(s, idx, 'C'); + if(next != -1) { + isGen(s, next, 4); + } + } else { + if(idx == s.length()) isOk = true; + else if(idx == s.length()-1 && s.charAt(idx) >= 'A' && s.charAt(idx) <= 'F') { + isOk = true; + } + } + } + public static int check(String s, int idx, char c) { + int i = idx; + while(i < s.length()) { + if(s.charAt(i) != c) break; + i++; + } + if(i > idx) { + return i; + } + return -1; + } + +} diff --git a/Programmers/Level2/JY_150369.java b/Programmers/Level2/JY_150369.java new file mode 100644 index 00000000..7cdb216a --- /dev/null +++ b/Programmers/Level2/JY_150369.java @@ -0,0 +1,53 @@ +import java.util.*; + +class Solution { + public long solution(int cap, int n, int[] deliveries, int[] pickups) { + long answer = 0; + + int i = n-1; + while(i >= 0) { + System.out.println("i: "+i); + System.out.println("d: "+Arrays.toString(deliveries)); + System.out.println("p: "+Arrays.toString(pickups)); + + // 배달과 수거 모두 끝난 집은 pass + if(deliveries[i] ==0 && pickups[i] ==0){ + i--; + continue; + } + + // 현재 가장 먼 집위치 + int start = i+1; + + // 배달하기 + int capD = cap; + int d = i; + while(d >= 0) { + if(capD < deliveries[d]) { + deliveries[d] -= capD; + break; + } + capD -= deliveries[d]; + deliveries[d] = 0; + d--; + } + + // 수거하기 + int capP = cap; + int p = i; + while(p >= 0) { + if(capP < pickups[p]) { + pickups[p] -= capP; + break; + } + capP -= pickups[p]; + pickups[p] = 0; + p--; + } + + answer += (start*2); + } + + return answer; + } +} \ No newline at end of file diff --git "a/SQL/08\354\243\274\354\260\250/JY_Game_Play_Analysis_IV.sql" "b/SQL/08\354\243\274\354\260\250/JY_Game_Play_Analysis_IV.sql" new file mode 100644 index 00000000..2f91d508 --- /dev/null +++ "b/SQL/08\354\243\274\354\260\250/JY_Game_Play_Analysis_IV.sql" @@ -0,0 +1,7 @@ +-- 550. Game Play Analysis IV +-- https://leetcode.com/problems/game-play-analysis-iv/?envType=study-plan-v2&envId=top-sql-50 +SELECT ROUND(COUNT(DISTINCT A.player_id) / (SELECT COUNT(DISTINCT player_id) FROM activity), 2) AS fraction +FROM activity A +JOIN activity B +on A.player_id = B.player_id +WHERE (A.player_id, A.event_date) in (SELECT player_id, min(event_date) FROM activity group by player_id) AND DATEDIFF(B.event_date, A.event_date) = 1 \ No newline at end of file diff --git "a/SQL/08\354\243\274\354\260\250/JY_Immediate_Food_Delivery_II.sql" "b/SQL/08\354\243\274\354\260\250/JY_Immediate_Food_Delivery_II.sql" new file mode 100644 index 00000000..7e3f59bb --- /dev/null +++ "b/SQL/08\354\243\274\354\260\250/JY_Immediate_Food_Delivery_II.sql" @@ -0,0 +1,6 @@ +-- 1174. Immediate Food Delivery II +-- https://leetcode.com/problems/immediate-food-delivery-ii/?envType=study-plan-v2&envId=top-sql-50 +select round(count(customer_id)/(select count(distinct customer_id) from delivery), 4)*100 as immediate_percentage +from delivery +where order_date = customer_pref_delivery_date + and (customer_id, order_date) in (select customer_id, min(order_date) from delivery group by customer_id) \ No newline at end of file