結果

問題 No.1006 Share an Integer
ユーザー htensaihtensai
提出日時 2020-03-25 12:43:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 3,598 ms
コンパイル使用メモリ 73,420 KB
実行使用メモリ 64,176 KB
最終ジャッジ日時 2023-08-30 09:31:46
合計ジャッジ時間 8,071 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,676 KB
testcase_01 AC 126 ms
55,600 KB
testcase_02 AC 127 ms
55,480 KB
testcase_03 AC 130 ms
55,360 KB
testcase_04 AC 131 ms
55,704 KB
testcase_05 AC 130 ms
55,784 KB
testcase_06 AC 128 ms
55,788 KB
testcase_07 AC 127 ms
55,296 KB
testcase_08 AC 127 ms
55,628 KB
testcase_09 AC 127 ms
55,856 KB
testcase_10 AC 125 ms
55,852 KB
testcase_11 AC 194 ms
60,000 KB
testcase_12 AC 235 ms
64,176 KB
testcase_13 AC 241 ms
64,080 KB
testcase_14 AC 238 ms
63,948 KB
testcase_15 AC 225 ms
63,972 KB
testcase_16 AC 181 ms
60,060 KB
testcase_17 AC 191 ms
60,064 KB
testcase_18 AC 228 ms
63,888 KB
testcase_19 AC 217 ms
64,072 KB
testcase_20 AC 224 ms
63,984 KB
testcase_21 AC 240 ms
63,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            arr[i] += i - 1;
            for (int j = 1; j * i < n; j++) {
                arr[i * j]--;
            }
        }
        ArrayList<Integer> mins = new ArrayList<>();
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < n; i++) {
            int x = Math.abs(arr[i] - arr[n - i]);
            if (min == x) {
                mins.add(i);
            } else if (min > x) {
                min = x;
                mins.clear();
                mins.add(i);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int x : mins) {
            sb.append(x).append(" ").append(n - x).append("\n");
        }
        System.out.print(sb);
    }
}
0