Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions lkhyun/202502/05 BOJ 골드2 등산.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
```java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
static BufferedReader br;
static BufferedWriter bw;
public static void main(String[] args) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int T = Integer.parseInt(st.nextToken());
int D = Integer.parseInt(st.nextToken());

int[][] map = new int[N][M];
for(int n=0;n<N;n++){
int temp=0;
for(char c : br.readLine().toCharArray()){
if(c>=97 && c<=122){
map[n][temp++] = c-'a' + 26;
}
else{
map[n][temp++] += c-'A';
}
}
}

long[][] shortpath = new long[N*M][N*M];
for(int i=0;i<N*M;i++){
Arrays.fill(shortpath[i],Integer.MAX_VALUE);
shortpath[i][i] = 0;
}
//상하좌우 순서서
int[] dx = {0,0,-1,1};
int[] dy = {-1,1,0,0};

for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
for(int m=0;m<4;m++){
int newi = i + dy[m];
int newj = j + dx[m];
if(newi >= 0 && newi < N && newj >= 0 && newj < M){
int height = map[newi][newj] - map[i][j];
if(Math.abs((double)height) > T){continue;}
if(height >= 0){//높은 곳에서 아래로 이동
shortpath[newi*M+newj][i*M+j] = 1;
shortpath[i*M+j][newi*M+newj] = (int)Math.pow(height,2);
}
else{
shortpath[newi*M+newj][i*M+j] = (int)Math.pow(height,2);
shortpath[i*M+j][newi*M+newj] = 1;
}

}
}
}
}
for(int x=0;x<N;x++){
for(int y=0;y<M;y++){
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
for(int k=0;k<N;k++){
for(int l=0;l<M;l++){
shortpath[i*M+j][k*M+l] = Math.min(shortpath[i*M+j][k*M+l],shortpath[i*M+j][x*M+y] + shortpath[x*M+y][k*M+l]);
}
}
}
}
}
}

int max = map[0][0];
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
if(shortpath[0][i*M+j] + shortpath[i*M+j][0] <= D){
max = Math.max(max,map[i][j]);
}
}
}
bw.write(max+"");
bw.flush();
}
}

```