Skip to content
Open
Changes from 1 commit
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
86 changes: 86 additions & 0 deletions 권혁준_19주차/[BOJ-1508] 레이스.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
```java
import java.util.*;
import java.io.*;

public 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, K;
static int[] A;

public static void main(String[] args) throws Exception {

ready();
solve();

bwEnd();

}

static void ready() throws Exception{

N = nextInt();
M = nextInt();
K = nextInt();
A = new int[K];
for(int i=0;i<K;i++) A[i] = nextInt();

}

static void solve() throws Exception {

int s = 0, e = 1000000, m = (s+e+1)>>1;
String answer = "";
while(s<e){
String result = check(m);
if(result == null) e = m-1;
else {
answer = result;
s = m;
}
m = (s+e+1)>>1;
}
bw.write(answer);

}

static String check(int dist) {

for(int st=0;st<=K-M;st++){
String res = "1";
int last = A[st], cnt = 1;
for(int i=st+1;i<K;i++){
if(A[i] - last < dist) res += '0';
else {
if(cnt < M){
res += '1';
last = A[i];
cnt++;
}
else res += '0';
}
}
if(cnt == M) return res;
}
return null;

}
Comment on lines +63 to +83
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문제를 풀다가 고민한 부분인데, 여태까지 모든 매개변수 탐색 문제를 풀 때 첫 번째 조건을 박아 놓고 시작했어. 무슨 말이냐면 이 문제 같은 경우 A[0]에 심판이 있다고 가정했단 말인데, 왜 이렇게 그리디하게 생각할 수 있는 거지? 첫 번째 위치에 심판이 없을 수도 있는거 아닌가?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 첫 시작 지점을 마음대로 정할 수 있어서 가능한 거라고 생각했어
A[0]에 심판이 없는 모든 경우는 A[0]에 심판이 있게 함으로써 항상 더 좋은 경우로 이끌어낼 수 있다고 생각했어


}
```