結果
問題 | No.2358 xy+yz+zx=N |
ユーザー | InTheBloom |
提出日時 | 2023-07-10 18:19:48 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 2,097 bytes |
コンパイル時間 | 1,554 ms |
コンパイル使用メモリ | 171,528 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-12 23:43:57 |
合計ジャッジ時間 | 2,770 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 82 ms
6,940 KB |
testcase_09 | AC | 84 ms
6,944 KB |
testcase_10 | AC | 71 ms
6,940 KB |
testcase_11 | AC | 73 ms
6,940 KB |
testcase_12 | AC | 53 ms
6,940 KB |
ソースコード
import std; void main () { long N = readln.chomp.to!long; solve(N); } struct trio { int X; int Y; int Z; } void solve (long N) { trio[] ans; // assume x <= y <= z foreach (x; 0..int.max) { if (N < x*x) { break; } foreach (y; x..int.max) { if (x == 0 && y == 0) { continue; } if (N < y*y) { break; } // z = (N-xy) / (x+y) if ((N-x*y) % (x+y) == 0) { if (y <= (N-x*y)/(x+y)) { ans ~= trio(x, y, cast(int) (N-x*y)/(x+y)); } } } } // counting length int len = 0; foreach (ref x; ans) { if (x.X != x.Y && x.X != x.Z && x.Y != x.Z) { len += 6; } else if (x.X == x.Y && x.X != x.Z) { len += 3; } else if (x.X != x.Y && x.Y == x.Z) { len += 3; } else if (x.X == x.Y && x.X == x.Z && x.Y == x.Z) { len += 1; } else { assert(0, "you can't reach this statement."); } } // output writeln(len); foreach (ref x; ans) { if (x.X != x.Y && x.X != x.Z && x.Y != x.Z) { writeln(x.X, " ", x.Y, " ", x.Z); writeln(x.X, " ", x.Z, " ", x.Y); writeln(x.Y, " ", x.X, " ", x.Z); writeln(x.Y, " ", x.Z, " ", x.X); writeln(x.Z, " ", x.X, " ", x.Y); writeln(x.Z, " ", x.Y, " ", x.X); } else if (x.X == x.Y && x.X != x.Z) { writeln(x.X, " ", x.Y, " ", x.Z); writeln(x.X, " ", x.Z, " ", x.Y); writeln(x.Z, " ", x.X, " ", x.Y); } else if (x.X != x.Y && x.Y == x.Z) { writeln(x.X, " ", x.Y, " ", x.Z); writeln(x.Y, " ", x.X, " ", x.Z); writeln(x.Y, " ", x.Z, " ", x.X); } else if (x.X == x.Y && x.X == x.Z && x.Y == x.Z) { writeln(x.X, " ", x.Y, " ", x.Z); } else { assert(0, "you can't reach this statement."); } } }