結果

問題 No.704 ゴミ拾い Medium
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-28 02:49:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 557 ms / 1,500 ms
コード長 2,734 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 74,452 KB
実行使用メモリ 74,208 KB
最終ジャッジ日時 2023-08-28 10:15:42
合計ジャッジ時間 18,422 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
54,872 KB
testcase_01 AC 57 ms
54,972 KB
testcase_02 AC 57 ms
55,136 KB
testcase_03 AC 58 ms
54,920 KB
testcase_04 AC 58 ms
54,964 KB
testcase_05 AC 59 ms
54,936 KB
testcase_06 AC 58 ms
54,960 KB
testcase_07 AC 58 ms
55,232 KB
testcase_08 AC 58 ms
55,100 KB
testcase_09 AC 57 ms
54,820 KB
testcase_10 AC 58 ms
54,948 KB
testcase_11 AC 59 ms
55,004 KB
testcase_12 AC 58 ms
54,836 KB
testcase_13 AC 59 ms
54,816 KB
testcase_14 AC 87 ms
56,248 KB
testcase_15 AC 85 ms
53,776 KB
testcase_16 AC 97 ms
55,996 KB
testcase_17 AC 85 ms
55,924 KB
testcase_18 AC 96 ms
55,528 KB
testcase_19 AC 89 ms
55,804 KB
testcase_20 AC 89 ms
55,548 KB
testcase_21 AC 87 ms
55,624 KB
testcase_22 AC 87 ms
55,832 KB
testcase_23 AC 86 ms
55,604 KB
testcase_24 AC 510 ms
74,152 KB
testcase_25 AC 500 ms
72,304 KB
testcase_26 AC 513 ms
71,208 KB
testcase_27 AC 511 ms
72,288 KB
testcase_28 AC 508 ms
68,396 KB
testcase_29 AC 528 ms
72,672 KB
testcase_30 AC 523 ms
73,708 KB
testcase_31 AC 506 ms
68,196 KB
testcase_32 AC 515 ms
68,952 KB
testcase_33 AC 489 ms
71,388 KB
testcase_34 AC 456 ms
70,652 KB
testcase_35 AC 459 ms
69,060 KB
testcase_36 AC 509 ms
70,656 KB
testcase_37 AC 463 ms
70,664 KB
testcase_38 AC 507 ms
69,528 KB
testcase_39 AC 473 ms
68,984 KB
testcase_40 AC 472 ms
66,960 KB
testcase_41 AC 497 ms
68,900 KB
testcase_42 AC 465 ms
71,012 KB
testcase_43 AC 476 ms
69,220 KB
testcase_44 AC 58 ms
54,872 KB
testcase_45 AC 58 ms
54,960 KB
testcase_46 AC 507 ms
74,208 KB
testcase_47 AC 557 ms
68,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        int[]a=sc.nextIntArray(n);
        int[]x=sc.nextIntArray(n);
        int[]y=sc.nextIntArray(n);
        MinBIT m1=new MinBIT();
        MinBIT p1=new MinBIT();
        int[]dp=new int[n+1];
        for(int i=0;i<n;++i){
            // update
            m1.update(300001-x[i],x[i]+y[i]+dp[i]);
            p1.update(1+x[i],-x[i]+y[i]+dp[i]);
            // query
            int ans=Integer.MAX_VALUE;
            int curA=a[i];
            ans=Math.min(ans,m1.query(300001-curA)-curA);
            ans=Math.min(ans,p1.query(curA+1)+curA);
            dp[i+1]=ans;
        }
        out.println(dp[n]);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}
class MinBIT {
    static final int SIZE = 1 << 19;
    static final int INFINITY = (1 << 30) - 1;
    int[] bit;
    MinBIT() {
	this.bit = new int[SIZE];
        Arrays.fill(this.bit,INFINITY);
    }
    void update(int x, int value) {
        while(x<SIZE){
            bit[x]=Math.min(bit[x],value);
            x+=x&(-x);
        }
    }
    int query(int x) {
        int y = INFINITY;
	while(x>0){
            y=Math.min(y,bit[x]);
            x&=x-1;
	}
	return y;
    }
}
0