diff --git "a/BOJ/20001-25000353円262円210円/JY_20181.java" "b/BOJ/20001-25000353円262円210円/JY_20181.java" new file mode 100644 index 00000000..825f7910 --- /dev/null +++ "b/BOJ/20001-25000353円262円210円/JY_20181.java" @@ -0,0 +1,41 @@ +import java.io.*; +import java.util.*; + +public class JY_20181 { + + 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 K = Integer.parseInt(st.nextToken()); + + long[] arr = new long[N+1]; + st = new StringTokenizer(br.readLine()); + for(int i=1; i= K) { + // dp[s-1]+sum-K : 시작 위치 + dp[e] = Math.max(dp[e], dp[s-1]+sum-K); + sum -= arr[s]; + s++; + } + e++; + } + System.out.println(dp[N]); + + } + +} diff --git "a/BOJ/20001-25000353円262円210円/JY_20291.java" "b/BOJ/20001-25000353円262円210円/JY_20291.java" new file mode 100644 index 00000000..75b0e0d1 --- /dev/null +++ "b/BOJ/20001-25000353円262円210円/JY_20291.java" @@ -0,0 +1,23 @@ +import java.io.*; +import java.util.*; + +public class JY_20291 { + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + Map fMap = new TreeMap(); + + int N = Integer.parseInt(st.nextToken()); + for(int i=0; i uList; + static int K; + static int ans; + + 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()); + H = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); + + g = new char[N][N]; + int sx = -1; + int sy = -1; + int ex = -1; + int ey = -1; + K = 0; + uList = new ArrayList(); + for(int i=0; i= ans) return; + + for(int i=0; i 다음 우산 위치의 거리 + int nDist = calDist(x, y, u[0], u[1]); + if(nDist> hp+up) continue; + + int nhp = hp; + // 체력이 소모 되는 경우 : 남은 우산 내구성 - 이동할 거리 + 1(다음위치도 우산이므로) + int tmp = up - nDist + 1; + if(tmp < 0) { + nhp += tmp; + } + visited[u[0]][u[1]] = true; + dfs(u[0], u[1], depth+nDist, nhp, D-1); + visited[u[0]][u[1]] = false; + } + } + +} diff --git "a/CodeTree/2021-2022353円205円204円/JY_354円203円211円352円271円224円355円217円255円355円203円204円.java" "b/CodeTree/2021-2022353円205円204円/JY_354円203円211円352円271円224円355円217円255円355円203円204円.java" new file mode 100644 index 00000000..b06e1888 --- /dev/null +++ "b/CodeTree/2021-2022353円205円204円/JY_354円203円211円352円271円224円355円217円255円355円203円204円.java" @@ -0,0 +1,224 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int N, M; + static int[][] g; + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + static boolean[][] visited; + static int rCnt; + static class Bomb implements Comparable { + int x, y, color; + + public Bomb(int x, int y, int color) { + super(); + this.x = x; + this.y = y; + this.color = color; + } + + @Override + public int compareTo(Bomb other) { + if(this.x == other.x) { + // 2) 열이 작은 순 + return this.y - other.y; + } + // 1) 행이 큰 순 + return other.x - this.x; + } + + @Override + public String toString() { + return "Bomb [x=" + x + ", y=" + y + ", color=" + color + "]"; + } + + } + + 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()); + + g = new int[N][N]; + for(int i=0; i bList = findBundle(); + + // 더이상 폭탄 묶음이 없으면 종료 + if(bList.size() == 0) break; + + // 폭탄 묶음 점수 계산 + int c = bList.size(); + ans += (c*c); + + // 2) 폭탄 제거 & 중력 작용 + removeBomb(bList); + + setGravity(); + + // 3) 반시계 90 회전 + rotate(); + + // 4) 중력 작용 + setGravity(); + + } + System.out.println(ans); + + } + public static void print(int[][] a) { + for(int i=0; i=0 && x=0 && y bfs(Bomb start) { + Queue q = new LinkedList(); + List aList = new ArrayList(); + + visited[start.x][start.y] = true; + q.add(start); + aList.add(start); + + // 빨간 폭탄 리스트 + List rList = new ArrayList(); + + while(!q.isEmpty()) { + Bomb now = q.poll(); + + for(int i=0; i<4; i++) { + int nx = now.x + dx[i]; + int ny = now.y + dy[i]; + + if(!inRange(nx, ny)) continue; + if(visited[nx][ny]) continue; + if(g[nx][ny] != 0 && g[nx][ny] != start.color) continue; + + Bomb next = new Bomb(nx, ny, g[nx][ny]); + if(g[nx][ny] == 0) { + rList.add(next); + } + + visited[nx][ny] = true; + q.add(next); + aList.add(next); + } + } + + rCnt = rList.size(); + // 빨간 폭탄들 visited 원상복귀 + for(Bomb r: rList) { + visited[r.x][r.y] = false; + } + + if(aList.size() <= 1) { + return new ArrayList(); + } + // 우선순위에 맞게 정렬 후 반환 + Collections.sort(aList); + return aList; + + } + public static List findBundle() { + // 기준점 우선순위 큐 (크기->빨간폭탄->행->열) + PriorityQueue pq = new PriorityQueue(new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if(o1[0] == o2[0]) { + if(o1[1] == o2[1]) { + if(o1[2] == o2[2]) { + // 4) 열이 작은 순 + return o1[3] - o2[3]; + } + // 3) 행이 큰 순 + return o2[2] - o1[2]; + } + // 2) 빨간 폭탄의 개수가 적은 순 + return o1[1] - o2[1]; + } + // 1) 묶음 크기가 큰 순 + return o2[0] - o1[0]; + } + }); + // 기준점의 위치와 폭탄 묶음 저장 해쉬맵 + Map> tMap = new HashMap(); + visited = new boolean[N][N]; + for(int i=0; i 0 && !visited[i][j]) { + rCnt = 0; + List bList = bfs(new Bomb(i, j, g[i][j])); + + if(bList.size() == 0) continue; + + Bomb center = bList.get(0); + int cNum = center.x*N + center.y; + if(tMap.getOrDefault(cNum, new ArrayList()).size()> bList.size()) { + continue; + } + tMap.put(cNum, bList); + pq.add(new int[] {bList.size(), rCnt, center.x, center.y}); + } + } + } + // pq가 비어있다면 만족하는 폭탄 묶음들 없음 + if(pq.size() == 0) return new ArrayList(); + // 가장 우선순위가 높은 기준점 + int[] target = pq.poll(); + return tMap.get(target[2]*N + target[3]); + + } + public static void removeBomb(List bList) { + // -2 : 빈칸 + for(Bomb b: bList) { + g[b.x][b.y] = -2; + } + } + public static void setGravity() { + for(int y=0; y=0; x--) { + if(g[x][y] < 0) continue; + + // 폭탄 + int color = g[x][y]; + g[x][y] = -2; + int t = x; + while(t < N) { + if(t+1 == N || g[t+1][y] != -2) break; + t++; + } + g[t][y] = color; + } + } + } + public static void rotate() { + int[][] t = new int[N][N]; + + for(int x=0; x "+"("+this.ex+","+this.ey+") sp:"+this.sp+" rCnt:"+this.rCnt; + } + } + + public int solution(int[][] points, int[][] routes) { + int answer = 0; + + // 로봇 초기화 + X = routes.length; + M = routes[0].length; + robots = new Robot[X+1]; + for(int i=0; i nDist) { + minDist = nDist; + nextX = nx; + nextY = ny; + } + } + // 이동 + now.x = nextX; + now.y = nextY; + + // 만약 목적지에 도착했다면 다음 목적지 갱신위헤 카운트 증가 + if(now.x == now.ex && now.y == now.ey) now.rCnt++; + } + } + public static boolean inRange(int x, int y) { + return x>0 && x<=n && y>0 && y<=n; + } + public static int check() { + g = new int[N+1][N+1]; + for(int i=1; i 1) cnt++; + } + } + + return cnt; + } + public static boolean isDone() { + for(int i=1; i[] g; + static Set gSet; + static Set sSet; + static PriorityQueue pq; + static class Node { + int edge, cost; + public Node(int edge, int cost) { + this.edge = edge; + this.cost = cost; + } + } + + public int[] solution(int n, int[][] paths, int[] gates, int[] summits) { + N = n; + g = new ArrayList[N+1]; + for(int i=1; i(); + } + + for(int i=0; i(); + for(int gate: gates) { + gSet.add(gate); + } + sSet = new HashSet(); + for(int summit: summits) { + sSet.add(summit); + } + + pq = new PriorityQueue((o1, o2) -> o1[1]==o2[1] ? o1[0]-o2[0] :o1[1]-o2[1]); + + // 산봉우리를 시작점으로 bfs + for(int summit: summits) { + bfs(summit); + } + + int[] answer = pq.poll(); + + return answer; + } + public static void bfs(int start) { + // 큐를 우선순위 큐로 설정하여, 비용이 작은 순부터 우선 탐색하도록 함 + PriorityQueue q = new PriorityQueue((o1, o2)-> o1[0]-o2[0]); + boolean[] visited = new boolean[N+1]; + + // {비용, 노드} + q.add(new int[] {0, start}); + visited[start] = true; + + int intensity = Integer.MAX_VALUE; + while(!q.isEmpty()) { + int[] now = q.poll(); + + // 출입구를 만남 + if(gSet.contains(now[1])) { + pq.add(new int[] {start, now[0]}); + break; + } + + // 등산로 반복 + for(Node next: g[now[1]]) { + if(sSet.contains(next.edge)) continue; + if(visited[next.edge]) continue; + + visited[now[1]] = true; + int max = Math.max(now[0], next.cost); + q.add(new int[] {max, next.edge}); + } + } + } +} \ No newline at end of file diff --git "a/SQL/14354円243円274円354円260円250円/JY_Confirmation_Rate.sql" "b/SQL/14354円243円274円354円260円250円/JY_Confirmation_Rate.sql" new file mode 100644 index 00000000..36bf237c --- /dev/null +++ "b/SQL/14354円243円274円354円260円250円/JY_Confirmation_Rate.sql" @@ -0,0 +1,11 @@ +-- 1934. Confirmation Rate +-- https://leetcode.com/problems/confirmation-rate/ +SELECT a.user_id + , CASE + WHEN COUNT(IF(action = "confirmed", a.user_id, null)) = 0 THEN round(0, 2) + ELSE ROUND(COUNT(IF(action = "confirmed", a.user_id, null)) / count(*), 2) + END AS confirmation_rate +FROM signups a +LEFT JOIN confirmations b +ON a.user_id = b.user_id +GROUP BY a.user_id \ No newline at end of file diff --git "a/SQL/14354円243円274円354円260円250円/JY_Game_Play_Analysis_IV.sql" "b/SQL/14354円243円274円354円260円250円/JY_Game_Play_Analysis_IV.sql" new file mode 100644 index 00000000..2b7a8f49 --- /dev/null +++ "b/SQL/14354円243円274円354円260円250円/JY_Game_Play_Analysis_IV.sql" @@ -0,0 +1,5 @@ +-- 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 player_id) / (SELECT COUNT(DISTINCT player_id) FROM activity), 2) AS fraction +FROM activity +WHERE (player_id, DATE_SUB(event_date, INTERVAL 1 DAY)) in (SELECT player_id, min(event_date) FROM activity group by player_id) \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /