結果
問題 | No.1006 Share an Integer |
ユーザー | tenten |
提出日時 | 2023-02-16 14:35:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 199 ms / 2,000 ms |
コード長 | 2,425 bytes |
コンパイル時間 | 3,321 ms |
コンパイル使用メモリ | 100,788 KB |
実行使用メモリ | 62,620 KB |
最終ジャッジ日時 | 2023-09-25 19:22:06 |
合計ジャッジ時間 | 6,381 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,648 KB |
testcase_01 | AC | 43 ms
49,728 KB |
testcase_02 | AC | 43 ms
50,148 KB |
testcase_03 | AC | 43 ms
49,664 KB |
testcase_04 | AC | 43 ms
49,856 KB |
testcase_05 | AC | 45 ms
49,652 KB |
testcase_06 | AC | 46 ms
50,156 KB |
testcase_07 | AC | 47 ms
49,936 KB |
testcase_08 | AC | 46 ms
49,812 KB |
testcase_09 | AC | 46 ms
50,032 KB |
testcase_10 | AC | 45 ms
49,884 KB |
testcase_11 | AC | 143 ms
58,120 KB |
testcase_12 | AC | 168 ms
61,876 KB |
testcase_13 | AC | 173 ms
62,188 KB |
testcase_14 | AC | 178 ms
61,996 KB |
testcase_15 | AC | 179 ms
62,620 KB |
testcase_16 | AC | 142 ms
58,104 KB |
testcase_17 | AC | 129 ms
59,912 KB |
testcase_18 | AC | 180 ms
62,268 KB |
testcase_19 | AC | 172 ms
62,272 KB |
testcase_20 | AC | 182 ms
62,076 KB |
testcase_21 | AC | 199 ms
62,372 KB |
ソースコード
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(); int[] values = new int[n + 1]; for (int i = 1; i <= n; i++) { values[i] += i; for (int j = 1; j * i <= n; j++) { values[j * i]--; } } int min = Integer.MAX_VALUE; ArrayList<Integer> ans = new ArrayList<>(); for (int i = 1; i * 2 <= n; i++) { int x = Math.abs(values[i] - values[n - i]); if (min > x) { min = x; ans.clear(); ans.add(i); if (i * 2 < n) { ans.add(n - i); } } else if (min == x) { ans.add(i); if (i * 2 < n) { ans.add(n - i); } } } Collections.sort(ans); StringBuilder sb = new StringBuilder(); for (int x : ans) { sb.append(x).append(" ").append(n - x).append("\n"); } System.out.print(sb); } } 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(); } }