답안 #255288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255288 2020-07-31T17:06:22 Z model_code Discharging (NOI20_discharging) Java 11
36 / 100
1000 ms 111484 KB
import java.io.*;
import java.util.*;

public class Discharging {
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
    }
    public static Vector<Double> intersect = new Vector<Double>();
    public static Vector<Long> grad = new Vector<Long>(),constant = new Vector<Long>();
    static boolean cmp(int a,int b,long g,long ct) {
        return (ct - constant.get(b))*(grad.get(a) - g) < (ct - constant.get(a))*(grad.get(b) - g);
    }
    public static double intersection(int a,long g,long ct){
        return ((double)constant.get(a)-(double)ct)/((double)g-(double)grad.get(a));
    }
    public static void popHull(){
        int a = constant.size()-1;
        constant.remove(a);
        grad.remove(a);
        intersect.remove(a);
    }
    public static void pushHull(double a,long b,long c){
        intersect.add(a);
        grad.add(b);
        constant.add(c);
    }
    public static void main(String[] args) throws IOException {
        Reader reader = new Reader();
        int N = reader.nextInt();
        long[] T = new long[N+1];
        for(int i = 1; i <= N; i++) {
            T[i] = reader.nextLong();
        }
        Vector<Long> dp = new Vector<Long>();
        dp.add(0L);
        pushHull(2e9,0l,0l);
        long curDpVal =0;
        long curMax = 0;
        int idx = 0;
        for(int i = 1; i <= N; i++){
            long curT = T[i];
            if(curT >= curMax){
                curMax = curT;
                while(intersect.get(idx)<(double)curMax)idx++;
                curDpVal = N*curMax + grad.get(idx) * curMax + constant.get(idx);
            }
            dp.add(curDpVal);
            long g = -i;
            long ct = dp.get(i);
            while(intersect.size()-idx >= 2 && cmp(intersect.size()-2,intersect.size()-1,g,ct)){
                popHull();
            }
            intersect.set(intersect.size()-1, intersection(intersect.size()-1,g,ct));
            pushHull(2e9,g,ct);
        }
        System.out.print(dp.get(N));
        // write code here
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 10244 KB Output is correct
2 Correct 76 ms 10048 KB Output is correct
3 Correct 85 ms 10092 KB Output is correct
4 Correct 83 ms 10136 KB Output is correct
5 Correct 74 ms 10200 KB Output is correct
6 Correct 78 ms 10408 KB Output is correct
7 Correct 78 ms 10168 KB Output is correct
8 Correct 80 ms 10116 KB Output is correct
9 Correct 79 ms 10020 KB Output is correct
10 Correct 77 ms 10144 KB Output is correct
11 Correct 77 ms 10020 KB Output is correct
12 Correct 81 ms 10272 KB Output is correct
13 Correct 75 ms 10288 KB Output is correct
14 Correct 85 ms 10152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 11044 KB Output is correct
2 Correct 97 ms 10680 KB Output is correct
3 Correct 94 ms 10604 KB Output is correct
4 Correct 102 ms 10812 KB Output is correct
5 Correct 105 ms 10704 KB Output is correct
6 Correct 100 ms 10620 KB Output is correct
7 Correct 97 ms 10692 KB Output is correct
8 Correct 98 ms 10628 KB Output is correct
9 Correct 101 ms 10688 KB Output is correct
10 Correct 134 ms 10704 KB Output is correct
11 Correct 103 ms 10836 KB Output is correct
12 Correct 94 ms 10672 KB Output is correct
13 Correct 93 ms 10660 KB Output is correct
14 Correct 94 ms 10448 KB Output is correct
15 Correct 92 ms 10704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 11044 KB Output is correct
2 Correct 97 ms 10680 KB Output is correct
3 Correct 94 ms 10604 KB Output is correct
4 Correct 102 ms 10812 KB Output is correct
5 Correct 105 ms 10704 KB Output is correct
6 Correct 100 ms 10620 KB Output is correct
7 Correct 97 ms 10692 KB Output is correct
8 Correct 98 ms 10628 KB Output is correct
9 Correct 101 ms 10688 KB Output is correct
10 Correct 134 ms 10704 KB Output is correct
11 Correct 103 ms 10836 KB Output is correct
12 Correct 94 ms 10672 KB Output is correct
13 Correct 93 ms 10660 KB Output is correct
14 Correct 94 ms 10448 KB Output is correct
15 Correct 92 ms 10704 KB Output is correct
16 Execution timed out 1110 ms 76960 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1028 ms 111484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 10244 KB Output is correct
2 Correct 76 ms 10048 KB Output is correct
3 Correct 85 ms 10092 KB Output is correct
4 Correct 83 ms 10136 KB Output is correct
5 Correct 74 ms 10200 KB Output is correct
6 Correct 78 ms 10408 KB Output is correct
7 Correct 78 ms 10168 KB Output is correct
8 Correct 80 ms 10116 KB Output is correct
9 Correct 79 ms 10020 KB Output is correct
10 Correct 77 ms 10144 KB Output is correct
11 Correct 77 ms 10020 KB Output is correct
12 Correct 81 ms 10272 KB Output is correct
13 Correct 75 ms 10288 KB Output is correct
14 Correct 85 ms 10152 KB Output is correct
15 Correct 96 ms 11044 KB Output is correct
16 Correct 97 ms 10680 KB Output is correct
17 Correct 94 ms 10604 KB Output is correct
18 Correct 102 ms 10812 KB Output is correct
19 Correct 105 ms 10704 KB Output is correct
20 Correct 100 ms 10620 KB Output is correct
21 Correct 97 ms 10692 KB Output is correct
22 Correct 98 ms 10628 KB Output is correct
23 Correct 101 ms 10688 KB Output is correct
24 Correct 134 ms 10704 KB Output is correct
25 Correct 103 ms 10836 KB Output is correct
26 Correct 94 ms 10672 KB Output is correct
27 Correct 93 ms 10660 KB Output is correct
28 Correct 94 ms 10448 KB Output is correct
29 Correct 92 ms 10704 KB Output is correct
30 Correct 96 ms 10860 KB Output is correct
31 Correct 92 ms 10728 KB Output is correct
32 Correct 96 ms 10592 KB Output is correct
33 Correct 90 ms 10564 KB Output is correct
34 Correct 113 ms 10736 KB Output is correct
35 Correct 84 ms 10644 KB Output is correct
36 Correct 88 ms 10532 KB Output is correct
37 Correct 98 ms 10724 KB Output is correct
38 Correct 96 ms 10624 KB Output is correct
39 Correct 91 ms 10480 KB Output is correct
40 Correct 90 ms 10600 KB Output is correct
41 Correct 87 ms 10856 KB Output is correct
42 Correct 95 ms 10616 KB Output is correct
43 Correct 98 ms 10724 KB Output is correct
44 Correct 97 ms 10512 KB Output is correct
45 Correct 101 ms 10360 KB Output is correct
46 Correct 95 ms 10856 KB Output is correct
47 Correct 90 ms 10488 KB Output is correct
48 Correct 103 ms 10612 KB Output is correct
49 Correct 88 ms 10616 KB Output is correct
50 Correct 88 ms 10616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 10244 KB Output is correct
2 Correct 76 ms 10048 KB Output is correct
3 Correct 85 ms 10092 KB Output is correct
4 Correct 83 ms 10136 KB Output is correct
5 Correct 74 ms 10200 KB Output is correct
6 Correct 78 ms 10408 KB Output is correct
7 Correct 78 ms 10168 KB Output is correct
8 Correct 80 ms 10116 KB Output is correct
9 Correct 79 ms 10020 KB Output is correct
10 Correct 77 ms 10144 KB Output is correct
11 Correct 77 ms 10020 KB Output is correct
12 Correct 81 ms 10272 KB Output is correct
13 Correct 75 ms 10288 KB Output is correct
14 Correct 85 ms 10152 KB Output is correct
15 Correct 96 ms 11044 KB Output is correct
16 Correct 97 ms 10680 KB Output is correct
17 Correct 94 ms 10604 KB Output is correct
18 Correct 102 ms 10812 KB Output is correct
19 Correct 105 ms 10704 KB Output is correct
20 Correct 100 ms 10620 KB Output is correct
21 Correct 97 ms 10692 KB Output is correct
22 Correct 98 ms 10628 KB Output is correct
23 Correct 101 ms 10688 KB Output is correct
24 Correct 134 ms 10704 KB Output is correct
25 Correct 103 ms 10836 KB Output is correct
26 Correct 94 ms 10672 KB Output is correct
27 Correct 93 ms 10660 KB Output is correct
28 Correct 94 ms 10448 KB Output is correct
29 Correct 92 ms 10704 KB Output is correct
30 Execution timed out 1110 ms 76960 KB Time limit exceeded
31 Halted 0 ms 0 KB -