답안 #366060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366060 2021-02-12T22:32:27 Z dapig Global Warming (CEOI18_glo) Java 11
100 / 100
432 ms 29104 KB
import java.io.*;
import java.util.*;

class glo {

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

		glo obj = new glo();

		obj.doStuff();

	}
	
	int binsearch(int val) {
		int l = 0, r = this.r;
		while (l < r) {
			int m = (l+r)/2;
			if (val < maxlist[m]) {
				if (val >= maxlist[m+1]) return m;
				l = m+1;
			} else r=m;
		}
		return l;
	}
	
	int[] maxlist; int r = 0;
	int[][] changes;
	void create() {
		maxlist = new int[nums.length+1];
		changes = new int[nums.length][2];
		Arrays.fill(maxlist, Integer.MIN_VALUE);
		maxlist[0] = Integer.MAX_VALUE;
		for (int i = nums.length-1; i >= 0; i--) {
			int pos = binsearch(nums[i]);
			pos++; r = Math.max(r, pos);
			changes[i] = new int[] {pos, maxlist[pos]};
			maxlist[pos] = nums[i];
		}
	}
	
	int binsearch2(int val) {
		int l = 0, r = this.r2;
		while (l < r) {
			int m = (l+r)/2;
			if (val > lis[m]) {
				if (val <= lis[m+1]) return m;
				l=m+1;
			} else r=m;
		}
		return l;
	}
	
	int find(int val) {
		int l = 1, r = maxlist.length-1;
		while (l<r) {
			int m = (l+r)/2;
			if (val >= maxlist[m]) {
				if (val < maxlist[m-1]) return m;
				r = m;
			} else l = m+1;
		}
		return l;
	}
	
	int[] lis; int r2 = 0;
	int process() {
		int ans = r;
		lis = new int[changes.length+1];
		Arrays.fill(lis, Integer.MAX_VALUE);
		lis[0] = Integer.MIN_VALUE;
		for (int i = 0; i < changes.length-1; i++) {
			maxlist[changes[i][0]] = changes[i][1];
			int pos = binsearch2(nums[i]);
			pos++; r2 = Math.max(r2, pos);
			lis[pos] = nums[i];
			int res = find(nums[i]-max)-1;
			ans = Math.max(ans, pos+res);
		}
		return ans;
	}

	int[] nums; int max;
	private void doStuff() throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		max = Integer.parseInt(st.nextToken());
		nums = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < nums.length; i++) {
			nums[i] = Integer.parseInt(st.nextToken());
		}
		br.close();
		
		create();
		System.out.println(process());
		
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 8532 KB Output is correct
2 Correct 70 ms 8544 KB Output is correct
3 Correct 82 ms 8556 KB Output is correct
4 Correct 71 ms 8552 KB Output is correct
5 Correct 70 ms 8556 KB Output is correct
6 Correct 70 ms 8428 KB Output is correct
7 Correct 72 ms 8668 KB Output is correct
8 Correct 71 ms 8796 KB Output is correct
9 Correct 74 ms 8560 KB Output is correct
10 Correct 85 ms 8448 KB Output is correct
11 Correct 73 ms 8448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 8532 KB Output is correct
2 Correct 70 ms 8544 KB Output is correct
3 Correct 82 ms 8556 KB Output is correct
4 Correct 71 ms 8552 KB Output is correct
5 Correct 70 ms 8556 KB Output is correct
6 Correct 70 ms 8428 KB Output is correct
7 Correct 72 ms 8668 KB Output is correct
8 Correct 71 ms 8796 KB Output is correct
9 Correct 74 ms 8560 KB Output is correct
10 Correct 85 ms 8448 KB Output is correct
11 Correct 73 ms 8448 KB Output is correct
12 Correct 73 ms 8428 KB Output is correct
13 Correct 73 ms 8556 KB Output is correct
14 Correct 75 ms 8556 KB Output is correct
15 Correct 74 ms 8684 KB Output is correct
16 Correct 71 ms 8540 KB Output is correct
17 Correct 70 ms 8556 KB Output is correct
18 Correct 69 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 8532 KB Output is correct
2 Correct 70 ms 8544 KB Output is correct
3 Correct 82 ms 8556 KB Output is correct
4 Correct 71 ms 8552 KB Output is correct
5 Correct 70 ms 8556 KB Output is correct
6 Correct 70 ms 8428 KB Output is correct
7 Correct 72 ms 8668 KB Output is correct
8 Correct 71 ms 8796 KB Output is correct
9 Correct 74 ms 8560 KB Output is correct
10 Correct 85 ms 8448 KB Output is correct
11 Correct 73 ms 8448 KB Output is correct
12 Correct 73 ms 8428 KB Output is correct
13 Correct 73 ms 8556 KB Output is correct
14 Correct 75 ms 8556 KB Output is correct
15 Correct 74 ms 8684 KB Output is correct
16 Correct 71 ms 8540 KB Output is correct
17 Correct 70 ms 8556 KB Output is correct
18 Correct 69 ms 8556 KB Output is correct
19 Correct 94 ms 8684 KB Output is correct
20 Correct 95 ms 8684 KB Output is correct
21 Correct 97 ms 8808 KB Output is correct
22 Correct 95 ms 8668 KB Output is correct
23 Correct 89 ms 8684 KB Output is correct
24 Correct 100 ms 8812 KB Output is correct
25 Correct 102 ms 8812 KB Output is correct
26 Correct 91 ms 8684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 427 ms 26804 KB Output is correct
2 Correct 410 ms 26464 KB Output is correct
3 Correct 418 ms 26584 KB Output is correct
4 Correct 412 ms 26616 KB Output is correct
5 Correct 409 ms 26948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 16244 KB Output is correct
2 Correct 326 ms 15988 KB Output is correct
3 Correct 310 ms 16228 KB Output is correct
4 Correct 329 ms 16636 KB Output is correct
5 Correct 69 ms 8428 KB Output is correct
6 Correct 321 ms 16608 KB Output is correct
7 Correct 316 ms 16880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 21072 KB Output is correct
2 Correct 365 ms 20944 KB Output is correct
3 Correct 405 ms 26504 KB Output is correct
4 Correct 407 ms 26812 KB Output is correct
5 Correct 357 ms 19672 KB Output is correct
6 Correct 418 ms 28968 KB Output is correct
7 Correct 407 ms 28900 KB Output is correct
8 Correct 360 ms 22168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 8532 KB Output is correct
2 Correct 70 ms 8544 KB Output is correct
3 Correct 82 ms 8556 KB Output is correct
4 Correct 71 ms 8552 KB Output is correct
5 Correct 70 ms 8556 KB Output is correct
6 Correct 70 ms 8428 KB Output is correct
7 Correct 72 ms 8668 KB Output is correct
8 Correct 71 ms 8796 KB Output is correct
9 Correct 74 ms 8560 KB Output is correct
10 Correct 85 ms 8448 KB Output is correct
11 Correct 73 ms 8448 KB Output is correct
12 Correct 73 ms 8428 KB Output is correct
13 Correct 73 ms 8556 KB Output is correct
14 Correct 75 ms 8556 KB Output is correct
15 Correct 74 ms 8684 KB Output is correct
16 Correct 71 ms 8540 KB Output is correct
17 Correct 70 ms 8556 KB Output is correct
18 Correct 69 ms 8556 KB Output is correct
19 Correct 94 ms 8684 KB Output is correct
20 Correct 95 ms 8684 KB Output is correct
21 Correct 97 ms 8808 KB Output is correct
22 Correct 95 ms 8668 KB Output is correct
23 Correct 89 ms 8684 KB Output is correct
24 Correct 100 ms 8812 KB Output is correct
25 Correct 102 ms 8812 KB Output is correct
26 Correct 91 ms 8684 KB Output is correct
27 Correct 427 ms 26804 KB Output is correct
28 Correct 410 ms 26464 KB Output is correct
29 Correct 418 ms 26584 KB Output is correct
30 Correct 412 ms 26616 KB Output is correct
31 Correct 409 ms 26948 KB Output is correct
32 Correct 321 ms 16244 KB Output is correct
33 Correct 326 ms 15988 KB Output is correct
34 Correct 310 ms 16228 KB Output is correct
35 Correct 329 ms 16636 KB Output is correct
36 Correct 69 ms 8428 KB Output is correct
37 Correct 321 ms 16608 KB Output is correct
38 Correct 316 ms 16880 KB Output is correct
39 Correct 361 ms 21072 KB Output is correct
40 Correct 365 ms 20944 KB Output is correct
41 Correct 405 ms 26504 KB Output is correct
42 Correct 407 ms 26812 KB Output is correct
43 Correct 357 ms 19672 KB Output is correct
44 Correct 418 ms 28968 KB Output is correct
45 Correct 407 ms 28900 KB Output is correct
46 Correct 360 ms 22168 KB Output is correct
47 Correct 360 ms 21956 KB Output is correct
48 Correct 381 ms 21772 KB Output is correct
49 Correct 425 ms 28560 KB Output is correct
50 Correct 407 ms 28036 KB Output is correct
51 Correct 392 ms 22464 KB Output is correct
52 Correct 398 ms 28104 KB Output is correct
53 Correct 410 ms 28120 KB Output is correct
54 Correct 432 ms 29104 KB Output is correct
55 Correct 405 ms 29104 KB Output is correct