結果
問題 | No.2358 xy+yz+zx=N |
ユーザー | tenten |
提出日時 | 2024-07-31 11:00:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 364 ms / 2,000 ms |
コード長 | 2,966 bytes |
コンパイル時間 | 2,526 ms |
コンパイル使用メモリ | 84,416 KB |
実行使用メモリ | 61,540 KB |
最終ジャッジ日時 | 2024-07-31 11:00:17 |
合計ジャッジ時間 | 6,638 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 105 ms
53,328 KB |
testcase_01 | AC | 102 ms
53,168 KB |
testcase_02 | AC | 104 ms
52,972 KB |
testcase_03 | AC | 104 ms
53,156 KB |
testcase_04 | AC | 106 ms
53,200 KB |
testcase_05 | AC | 105 ms
53,128 KB |
testcase_06 | AC | 101 ms
51,708 KB |
testcase_07 | AC | 139 ms
53,744 KB |
testcase_08 | AC | 328 ms
61,512 KB |
testcase_09 | AC | 364 ms
61,540 KB |
testcase_10 | AC | 318 ms
57,648 KB |
testcase_11 | AC | 285 ms
58,392 KB |
testcase_12 | AC | 315 ms
58,896 KB |
ソースコード
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 n = sc.nextInt(); List<Answer> ans = new ArrayList<>(); int count = 0; for (int i = 0; i <= Math.sqrt(n); i++) { for (int j = i; j <= Math.sqrt(n); j++) { if (i == 0 && j == 0) { continue; } if ((n - i * j) % (i + j) == 0 && (n - i * j) / (i + j) >= j) { Answer current = new Answer(i, j, (n - i * j) / (i + j)); count += current.size(); ans.add(current); } } } System.out.println(count); System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n"))); } static class Answer { Set<Three> threes = new HashSet<>(); public Answer(int a, int b, int c) { threes.add(new Three(a, b, c)); threes.add(new Three(a, c, b)); threes.add(new Three(b, a, c)); threes.add(new Three(b, c, a)); threes.add(new Three(c, a, b)); threes.add(new Three(c, b, a)); } public int size() { return threes.size(); } public String toString() { return threes.stream().map(x -> x.toString()).collect(Collectors.joining("\n")); } } static class Three { int a; int b; int c; public Three(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } public int hashCode() { return Objects.hash(a, b, c); } public boolean equals(Object o) { Three x = (Three)o; return a == x.a && b == x.b && c == x.c; } public String toString() { return a + " " + b + " " + c; } } } 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(); } } }