結果

問題 No.602 隠されていたゲーム2
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-02 00:28:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 3,328 bytes
コンパイル時間 2,526 ms
コンパイル使用メモリ 76,828 KB
実行使用メモリ 66,148 KB
最終ジャッジ日時 2023-08-22 05:33:00
合計ジャッジ時間 6,527 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
47,484 KB
testcase_01 AC 43 ms
49,668 KB
testcase_02 AC 42 ms
49,980 KB
testcase_03 AC 43 ms
49,536 KB
testcase_04 AC 42 ms
47,960 KB
testcase_05 AC 43 ms
49,636 KB
testcase_06 AC 43 ms
49,692 KB
testcase_07 AC 44 ms
49,484 KB
testcase_08 AC 45 ms
47,432 KB
testcase_09 AC 45 ms
49,504 KB
testcase_10 AC 46 ms
49,572 KB
testcase_11 AC 45 ms
49,780 KB
testcase_12 AC 44 ms
49,488 KB
testcase_13 AC 44 ms
49,480 KB
testcase_14 AC 44 ms
49,540 KB
testcase_15 AC 44 ms
49,480 KB
testcase_16 AC 160 ms
57,056 KB
testcase_17 AC 211 ms
56,144 KB
testcase_18 AC 317 ms
64,276 KB
testcase_19 AC 376 ms
66,148 KB
testcase_20 AC 327 ms
64,980 KB
testcase_21 AC 285 ms
63,684 KB
testcase_22 AC 356 ms
64,136 KB
testcase_23 AC 264 ms
63,688 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();
        long[]d=new long[n];
        long[]a=new long[n],b=new long[n];
        int p=0,q=0;
        Set<Long>hs=new HashSet<Long>();
        long e=-1,o=-1;
        for(int i=0;i<n;++i){
            d[i]=sc.nextLong();hs.add(d[i]);
            if(d[i]%2==1){
                o=Math.max(o,d[i]);
                b[q++]=d[i];
            }else{
                e=Math.max(e,d[i]);
                a[p++]=d[i];
            }
        }
        Arrays.sort(a,0,p);
        Arrays.sort(b,0,q);
        long x=sc.nextLong(),y=sc.nextLong();
        long dd=Math.abs(x)+Math.abs(y);
        if(dd==0){
            out.println(0);
            out.close();
            return;
        }
        if(hs.contains(dd)){
            out.println(1);
            out.close();
            return;
        }
        if(dd%2==0){
            if(dd<=2*e||dd<=2*o)
                out.println(2);
            else
                out.println(-1);
        }else{
            if(e<0||o<0){
                out.println(-1);
                out.close();
                return;
            }
            boolean ok=false;
            for(long xx:Arrays.copyOf(a,p)){
                int l=Arrays.binarySearch(b,0,q,Math.abs(dd-xx)-1);
                if(l<0)l=-l-1;
                int r=Arrays.binarySearch(b,0,q,dd+xx+1);
                if(r<0)r=-r-1;
                if(l<r){
                    ok=true;
                    break;
                }
            }
            for(long xx:Arrays.copyOf(b,q)){
                int l=Arrays.binarySearch(a,0,p,Math.abs(dd-xx)-1);
                if(l<0)l=-l-1;
                int r=Arrays.binarySearch(a,0,p,dd+xx+1);
                if(r<0)r=-r-1;
                if(l<r){
                    ok=true;
                    break;
                }
            }
            out.println(ok?2:-1);
        }
        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;
        }
    }
}
0