답안 #583998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583998 2022-06-26T16:03:37 Z DylanSmith Rabbit Carrot (LMIO19_triusis) Java 11
100 / 100
646 ms 55916 KB
import java.util.*;
import java.io.*;
public class triusis {
    public static void main(String[] args) throws IOException {
        Reader in = new Reader();
        PrintWriter out = new PrintWriter(System.out);
        
        int N = in.nextInt() + 1, K = in.nextInt();
        long[] arr = new long[N];
        for (int i = 1; i < N; i++) {
            int h = in.nextInt();
            arr[i] = h - i * K;
        }
        TreeSet<Long> set = new TreeSet<>();
        for (long i : arr) {
            set.add(i);
        }
        HashMap<Long, Integer> map = new HashMap<>();
        int index = 0;
        for (long i : set) {
            map.put(i, index++);
        }
        int[] arr2 = new int[N];
        for (int i = 0; i < N; i++) {
            arr2[i] = map.get(arr[i]);
        }
        int M = 1;
        while (M < 200001) {
            M <<= 1;
        }
        int[] tree = new int[M * 2];
        for (int i = 0; i < N; i++) {
            int l = arr2[i] + M, r = M * 2 - 1;
            int max = 0;
            while (l <= r) {
                if (l % 2 == 1) {
                    max = Math.max(max, tree[l]);
                    l >>= 1;
                    l++;
                } else {
                    l >>= 1;
                }
                if (r % 2 == 0) {
                    max = Math.max(max, tree[r]);
                    r >>= 1;
                    r--;
                } else {
                    r >>= 1;
                }
            }
            if (i > 0 && max == 0) {
                continue;
            }
            max++;
            int current = arr2[i] + M;
            while (current > 0) {
                tree[current] = Math.max(tree[current], max);
                current >>= 1;
            }
        }
        out.println(N - tree[1]);
        
        out.close();
    }
    static class Reader {
        BufferedInputStream in;
        public Reader() {
            in = new BufferedInputStream(System.in);
        }
        public String nextLine() throws IOException {
            int c;
            StringBuilder sb = new StringBuilder("");
            while ((c = in.read()) != '\n')
                sb.append((char)(c));
            return sb.toString();
        }
        public String next() throws IOException {
            int c;
            StringBuilder sb = new StringBuilder("");
            while ((c = in.read()) != ' ' && c != '\n')
                sb.append((char)(c));
            return sb.toString();
        }
        public int nextInt() throws IOException {
            return (int)nextLong();
        }
        public long nextLong() throws IOException {
            int c;
            long res = 0;
            boolean start = false, negative = false;
            while ((c = in.read()) != ' ' && c != '\n' || !start)
                if (c >= '0' && c <= '9' || c == '-') {
                    start = true;
                    if (c == '-')
                        negative = true;
                    else
                        res = res * 10 + c - '0';
                }
            return res * (negative ? -1 : 1);
        }
    }
    public static void sort(int[] arr) {
        List<Integer> list = new ArrayList<>();
        for (int i : arr) {
            list.add(i);
        }
        Collections.sort(list);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = list.get(i);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 10124 KB Output is correct
2 Correct 60 ms 10436 KB Output is correct
3 Correct 65 ms 10256 KB Output is correct
4 Correct 74 ms 10188 KB Output is correct
5 Correct 61 ms 10300 KB Output is correct
6 Correct 67 ms 10476 KB Output is correct
7 Correct 58 ms 10028 KB Output is correct
8 Correct 60 ms 10340 KB Output is correct
9 Correct 67 ms 10248 KB Output is correct
10 Correct 61 ms 10184 KB Output is correct
11 Correct 69 ms 10212 KB Output is correct
12 Correct 59 ms 10456 KB Output is correct
13 Correct 58 ms 10288 KB Output is correct
14 Correct 63 ms 10444 KB Output is correct
15 Correct 60 ms 10356 KB Output is correct
16 Correct 73 ms 10200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 10124 KB Output is correct
2 Correct 60 ms 10436 KB Output is correct
3 Correct 65 ms 10256 KB Output is correct
4 Correct 74 ms 10188 KB Output is correct
5 Correct 61 ms 10300 KB Output is correct
6 Correct 67 ms 10476 KB Output is correct
7 Correct 58 ms 10028 KB Output is correct
8 Correct 60 ms 10340 KB Output is correct
9 Correct 67 ms 10248 KB Output is correct
10 Correct 61 ms 10184 KB Output is correct
11 Correct 69 ms 10212 KB Output is correct
12 Correct 59 ms 10456 KB Output is correct
13 Correct 58 ms 10288 KB Output is correct
14 Correct 63 ms 10444 KB Output is correct
15 Correct 60 ms 10356 KB Output is correct
16 Correct 73 ms 10200 KB Output is correct
17 Correct 67 ms 10248 KB Output is correct
18 Correct 62 ms 10204 KB Output is correct
19 Correct 66 ms 10312 KB Output is correct
20 Correct 153 ms 12736 KB Output is correct
21 Correct 124 ms 12444 KB Output is correct
22 Correct 125 ms 12432 KB Output is correct
23 Correct 141 ms 12828 KB Output is correct
24 Correct 130 ms 12688 KB Output is correct
25 Correct 123 ms 12436 KB Output is correct
26 Correct 126 ms 12616 KB Output is correct
27 Correct 95 ms 10900 KB Output is correct
28 Correct 102 ms 10748 KB Output is correct
29 Correct 125 ms 12620 KB Output is correct
30 Correct 127 ms 12508 KB Output is correct
31 Correct 141 ms 12484 KB Output is correct
32 Correct 146 ms 12856 KB Output is correct
33 Correct 161 ms 12764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 10248 KB Output is correct
2 Correct 62 ms 10204 KB Output is correct
3 Correct 66 ms 10312 KB Output is correct
4 Correct 153 ms 12736 KB Output is correct
5 Correct 124 ms 12444 KB Output is correct
6 Correct 125 ms 12432 KB Output is correct
7 Correct 141 ms 12828 KB Output is correct
8 Correct 130 ms 12688 KB Output is correct
9 Correct 123 ms 12436 KB Output is correct
10 Correct 126 ms 12616 KB Output is correct
11 Correct 95 ms 10900 KB Output is correct
12 Correct 102 ms 10748 KB Output is correct
13 Correct 125 ms 12620 KB Output is correct
14 Correct 127 ms 12508 KB Output is correct
15 Correct 141 ms 12484 KB Output is correct
16 Correct 146 ms 12856 KB Output is correct
17 Correct 161 ms 12764 KB Output is correct
18 Correct 64 ms 10124 KB Output is correct
19 Correct 60 ms 10436 KB Output is correct
20 Correct 65 ms 10256 KB Output is correct
21 Correct 74 ms 10188 KB Output is correct
22 Correct 61 ms 10300 KB Output is correct
23 Correct 67 ms 10476 KB Output is correct
24 Correct 58 ms 10028 KB Output is correct
25 Correct 60 ms 10340 KB Output is correct
26 Correct 67 ms 10248 KB Output is correct
27 Correct 61 ms 10184 KB Output is correct
28 Correct 69 ms 10212 KB Output is correct
29 Correct 59 ms 10456 KB Output is correct
30 Correct 58 ms 10288 KB Output is correct
31 Correct 63 ms 10444 KB Output is correct
32 Correct 60 ms 10356 KB Output is correct
33 Correct 73 ms 10200 KB Output is correct
34 Correct 134 ms 12820 KB Output is correct
35 Correct 157 ms 12936 KB Output is correct
36 Correct 129 ms 12936 KB Output is correct
37 Correct 122 ms 12820 KB Output is correct
38 Correct 88 ms 10692 KB Output is correct
39 Correct 97 ms 10920 KB Output is correct
40 Correct 152 ms 12528 KB Output is correct
41 Correct 90 ms 10928 KB Output is correct
42 Correct 145 ms 12840 KB Output is correct
43 Correct 127 ms 12708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 12820 KB Output is correct
2 Correct 157 ms 12936 KB Output is correct
3 Correct 129 ms 12936 KB Output is correct
4 Correct 122 ms 12820 KB Output is correct
5 Correct 88 ms 10692 KB Output is correct
6 Correct 97 ms 10920 KB Output is correct
7 Correct 152 ms 12528 KB Output is correct
8 Correct 90 ms 10928 KB Output is correct
9 Correct 145 ms 12840 KB Output is correct
10 Correct 127 ms 12708 KB Output is correct
11 Correct 67 ms 10248 KB Output is correct
12 Correct 62 ms 10204 KB Output is correct
13 Correct 66 ms 10312 KB Output is correct
14 Correct 153 ms 12736 KB Output is correct
15 Correct 124 ms 12444 KB Output is correct
16 Correct 125 ms 12432 KB Output is correct
17 Correct 141 ms 12828 KB Output is correct
18 Correct 130 ms 12688 KB Output is correct
19 Correct 123 ms 12436 KB Output is correct
20 Correct 126 ms 12616 KB Output is correct
21 Correct 95 ms 10900 KB Output is correct
22 Correct 102 ms 10748 KB Output is correct
23 Correct 125 ms 12620 KB Output is correct
24 Correct 127 ms 12508 KB Output is correct
25 Correct 141 ms 12484 KB Output is correct
26 Correct 146 ms 12856 KB Output is correct
27 Correct 161 ms 12764 KB Output is correct
28 Correct 64 ms 10124 KB Output is correct
29 Correct 60 ms 10436 KB Output is correct
30 Correct 65 ms 10256 KB Output is correct
31 Correct 74 ms 10188 KB Output is correct
32 Correct 61 ms 10300 KB Output is correct
33 Correct 67 ms 10476 KB Output is correct
34 Correct 58 ms 10028 KB Output is correct
35 Correct 60 ms 10340 KB Output is correct
36 Correct 67 ms 10248 KB Output is correct
37 Correct 61 ms 10184 KB Output is correct
38 Correct 69 ms 10212 KB Output is correct
39 Correct 59 ms 10456 KB Output is correct
40 Correct 58 ms 10288 KB Output is correct
41 Correct 63 ms 10444 KB Output is correct
42 Correct 60 ms 10356 KB Output is correct
43 Correct 73 ms 10200 KB Output is correct
44 Correct 478 ms 53376 KB Output is correct
45 Correct 608 ms 54912 KB Output is correct
46 Correct 637 ms 55916 KB Output is correct
47 Correct 646 ms 54940 KB Output is correct
48 Correct 420 ms 51852 KB Output is correct
49 Correct 493 ms 54060 KB Output is correct
50 Correct 172 ms 17052 KB Output is correct
51 Correct 226 ms 17428 KB Output is correct
52 Correct 352 ms 32804 KB Output is correct
53 Correct 156 ms 15836 KB Output is correct
54 Correct 447 ms 53912 KB Output is correct
55 Correct 444 ms 53704 KB Output is correct