답안 #318741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318741 2020-11-03T05:05:47 Z anishrajeev Cipele (COCI18_cipele) Java 11
45 / 90
1000 ms 43212 KB
import java.io.*;
import java.util.*;

public class cipele {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader bf = new BufferedReader(new FileReader("tester.in"));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer stk = new StringTokenizer(bf.readLine());
        int N = Integer.parseInt(stk.nextToken());
        int M = Integer.parseInt(stk.nextToken());
        ArrayList<Integer> less = new ArrayList<>();
        ArrayList<Integer> more = new ArrayList<>();
        if(N < M){
            stk = new StringTokenizer(bf.readLine());
            for(int i = 0; i < N; i++)less.add(Integer.parseInt(stk.nextToken()));
            stk = new StringTokenizer(bf.readLine());
            for(int i = 0; i < M; i++)more.add(Integer.parseInt(stk.nextToken()));
        }
        else{
            stk = new StringTokenizer(bf.readLine());
            for(int i = 0; i < N; i++)more.add(Integer.parseInt(stk.nextToken()));
            stk = new StringTokenizer(bf.readLine());
            for(int i = 0; i < M; i++)less.add(Integer.parseInt(stk.nextToken()));
        }
        Collections.sort(less);
        Collections.sort(more);
        int start = 0, end = Integer.MAX_VALUE;
        while(start!=end){
            int mid = (start+end)/2;
            if(verify(less,more, mid)) end = mid;
            else start = mid+1;
        }
        System.out.println(start);
    }
    public static boolean verify(ArrayList<Integer> less, ArrayList<Integer> more, int target){
        int l = 0;
        int m = 0;
        while(l < less.size()){
            boolean matched = false;
            int matchnum = 0;
            for(int i = m; i < more.size(); i++){
                if(Math.abs(more.get(i)-less.get(l)) <= target){
                    matched = true;
                    matchnum = i;
                    break;
                }
            }
            if(matched)m = matchnum+1;
            else return false;
            l++;
        }
        return true;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 37616 KB Output is correct
2 Execution timed out 1018 ms 43212 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1028 ms 41644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 12400 KB Output is correct
2 Correct 271 ms 16272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 12644 KB Output is correct
2 Correct 298 ms 16328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 13920 KB Output is correct
2 Correct 296 ms 16448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 13520 KB Output is correct
2 Correct 293 ms 16340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 14256 KB Output is correct
2 Correct 288 ms 16132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1048 ms 39272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1014 ms 41144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1027 ms 38072 KB Time limit exceeded
2 Halted 0 ms 0 KB -