From d32fc9200999536cca8aa71e90aaf2a7ef0b81ce Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 8 Apr 2025 17:14:34 +0900 Subject: [PATCH] =?UTF-8?q?[20250408]=20BOJ=20/=20G1=20/=20=EB=8B=AC?= =?UTF-8?q?=EC=9D=B4=20=EC=B0=A8=EC=98=A4=EB=A5=B8=EB=8B=A4,=20=EA=B0=80?= =?UTF-8?q?=EC=9E=90.=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\213\244, \352\260\200\354\236\220.md" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "khj20006/202504/08 BOJ G1 \353\213\254\354\235\264 \354\260\250\354\230\244\353\245\270\353\213\244, \352\260\200\354\236\220.md" diff --git "a/khj20006/202504/08 BOJ G1 \353\213\254\354\235\264 \354\260\250\354\230\244\353\245\270\353\213\244, \352\260\200\354\236\220.md" "b/khj20006/202504/08 BOJ G1 \353\213\254\354\235\264 \354\260\250\354\230\244\353\245\270\353\213\244, \352\260\200\354\236\220.md" new file mode 100644 index 00000000..7e99f453 --- /dev/null +++ "b/khj20006/202504/08 BOJ G1 \353\213\254\354\235\264 \354\260\250\354\230\244\353\245\270\353\213\244, \352\260\200\354\236\220.md" @@ -0,0 +1,83 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N, M; + static char[][] A; + static int[] start; + + static int[] dx = {1,0,-1,0}; + static int[] dy = {0,1,0,-1}; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + A = new char[N][M]; + for(int i=0;i Q = new LinkedList<>(); + vis[start[0]][start[1]][0] = true; + Q.offer(new int[] {start[0], start[1], 0, 0}); + while(!Q.isEmpty()) { + int[] now = Q.poll(); + int x = now[0], y = now[1], keys = now[2], t = now[3]; + if(A[x][y] == '1') { + bw.write(t + "\n"); + return; + } + for(int i=0;i<4;i++) { + int xx = x+dx[i], yy = y+dy[i]; + if(xx<0 || xx>=N || yy<0 || yy>=M || A[xx][yy] == '#') continue; + int nkeys = keys; + if(A[xx][yy] >= 'a') nkeys |= (1<<(A[xx][yy]-'a')); + if('A' <= A[xx][yy] && A[xx][yy] <= 'F' && (nkeys & (1<<(A[xx][yy]-'A'))) == 0) continue; + if(vis[xx][yy][nkeys]) continue; + vis[xx][yy][nkeys] = true; + Q.offer(new int[] {xx,yy,nkeys,t+1}); + } + } + bw.write("-1"); + + } + +} + +```