結果

問題 No.1884 Sequence
ユーザー tentententen
提出日時 2023-08-08 11:26:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,689 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 91,876 KB
実行使用メモリ 60,116 KB
最終ジャッジ日時 2024-04-26 04:27:36
合計ジャッジ時間 18,614 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,316 KB
testcase_01 AC 53 ms
37,264 KB
testcase_02 AC 52 ms
37,036 KB
testcase_03 AC 51 ms
37,440 KB
testcase_04 AC 51 ms
37,296 KB
testcase_05 AC 52 ms
37,208 KB
testcase_06 AC 52 ms
37,208 KB
testcase_07 AC 51 ms
37,408 KB
testcase_08 AC 52 ms
36,792 KB
testcase_09 AC 52 ms
37,300 KB
testcase_10 AC 830 ms
57,208 KB
testcase_11 AC 856 ms
58,632 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 218 ms
45,716 KB
testcase_15 AC 481 ms
57,548 KB
testcase_16 AC 611 ms
56,760 KB
testcase_17 AC 296 ms
50,236 KB
testcase_18 AC 364 ms
56,640 KB
testcase_19 AC 335 ms
51,404 KB
testcase_20 AC 417 ms
52,080 KB
testcase_21 AC 347 ms
49,272 KB
testcase_22 AC 442 ms
52,816 KB
testcase_23 AC 617 ms
58,616 KB
testcase_24 AC 632 ms
57,180 KB
testcase_25 AC 600 ms
59,596 KB
testcase_26 AC 645 ms
60,116 KB
testcase_27 AC 209 ms
45,728 KB
testcase_28 AC 192 ms
44,772 KB
testcase_29 AC 189 ms
45,044 KB
testcase_30 AC 209 ms
45,452 KB
testcase_31 AC 409 ms
52,956 KB
testcase_32 AC 644 ms
58,852 KB
testcase_33 AC 366 ms
55,700 KB
testcase_34 AC 361 ms
56,456 KB
testcase_35 AC 221 ms
45,684 KB
testcase_36 AC 329 ms
55,160 KB
testcase_37 AC 364 ms
56,596 KB
testcase_38 AC 350 ms
56,008 KB
testcase_39 AC 259 ms
46,260 KB
testcase_40 AC 267 ms
48,856 KB
testcase_41 AC 602 ms
58,244 KB
testcase_42 AC 565 ms
57,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        ArrayList<Long> list = new ArrayList<>();
        long count = 0;
        for (int i = 0; i < n; i++) {
            long x = sc.nextLong();
            if (x == 0) {
                count++;
            } else {
                list.add(x);
            }
        }
        if (list.size() <= 1) {
            System.out.println("Yes");
            return;
        }
        Collections.sort(list);
        ArrayList<Long> diff = new ArrayList<>();
        for (int i = 0; i < list.size() - 1; i++) {
            diff.add(list.get(i + 1) - list.get(i));
        }
        Collections.sort(diff);
        if (diff.get(0) == 0) {
            if (diff.get(diff.size() - 1) == 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
            return;
        }
        for (int i = 1; i < diff.size() && count >= 0; i++) {
            if (diff.get(i) % diff.get(0) == 0) {
                count -= diff.get(i) / diff.get(0) - 1;
            } else {
                System.out.println("No");
                return;
            }
        }
        if (count >= 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0