結果

問題 No.2542 Yokan for Two
ユーザー tentententen
提出日時 2024-04-05 17:54:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 460 ms / 2,000 ms
コード長 1,882 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 79,600 KB
実行使用メモリ 71,056 KB
最終ジャッジ日時 2024-04-05 17:54:23
合計ジャッジ時間 13,693 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,988 KB
testcase_01 AC 47 ms
53,984 KB
testcase_02 AC 46 ms
53,992 KB
testcase_03 AC 156 ms
61,188 KB
testcase_04 AC 186 ms
61,580 KB
testcase_05 AC 335 ms
69,804 KB
testcase_06 AC 48 ms
53,984 KB
testcase_07 AC 460 ms
71,056 KB
testcase_08 AC 231 ms
66,932 KB
testcase_09 AC 427 ms
70,664 KB
testcase_10 AC 133 ms
59,228 KB
testcase_11 AC 164 ms
59,316 KB
testcase_12 AC 331 ms
68,724 KB
testcase_13 AC 134 ms
59,276 KB
testcase_14 AC 243 ms
68,416 KB
testcase_15 AC 296 ms
68,636 KB
testcase_16 AC 259 ms
69,264 KB
testcase_17 AC 247 ms
69,124 KB
testcase_18 AC 273 ms
70,040 KB
testcase_19 AC 198 ms
63,252 KB
testcase_20 AC 209 ms
60,672 KB
testcase_21 AC 205 ms
60,844 KB
testcase_22 AC 189 ms
60,856 KB
testcase_23 AC 198 ms
63,208 KB
testcase_24 AC 49 ms
53,980 KB
testcase_25 AC 47 ms
53,996 KB
testcase_26 AC 49 ms
53,976 KB
testcase_27 AC 48 ms
54,012 KB
testcase_28 AC 48 ms
53,968 KB
testcase_29 AC 243 ms
67,192 KB
testcase_30 AC 280 ms
68,668 KB
testcase_31 AC 234 ms
68,192 KB
testcase_32 AC 255 ms
69,140 KB
testcase_33 AC 254 ms
68,668 KB
testcase_34 AC 279 ms
68,988 KB
testcase_35 AC 274 ms
68,956 KB
testcase_36 AC 247 ms
69,092 KB
testcase_37 AC 298 ms
69,084 KB
testcase_38 AC 299 ms
68,828 KB
testcase_39 AC 292 ms
69,692 KB
testcase_40 AC 284 ms
69,652 KB
testcase_41 AC 254 ms
69,448 KB
testcase_42 AC 310 ms
69,548 KB
testcase_43 AC 254 ms
69,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int length = sc.nextInt();
        int n = sc.nextInt();
        int[] positions = new int[n];
        for (int i = 0; i < n; i++) {
            positions[i] = sc.nextInt();
        }
        int base = Math.abs(length - positions[n - 1] - positions[0]);
        Set<Integer> current = new HashSet<>();
        current.add(0);
        for (int i = 0; i < n - 1; i++) {
            int x = positions[i + 1] - positions[i];
            Set<Integer> next = new HashSet<>();
            for (int y : current) {
                next.add(x + y);
                next.add(Math.abs(y - x));
            }
            current = next;
        }
        int ans = Integer.MAX_VALUE;
        for (int x : current) {
            ans = Math.min(ans, Math.abs(base - x));
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0