結果

問題 No.2358 xy+yz+zx=N
ユーザー luanmengleiluanmenglei
提出日時 2023-06-23 22:32:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 209,916 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 10:12:46
合計ジャッジ時間 4,025 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<array<int, 3>> ans, nans;
int n;

void check(int x, int y) {
	if ((n - x * y) % (x + y) != 0) return;
	int z = (n - x * y) / (x + y);
	ans.push_back({ x, y, z });
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int xy = 1; xy * xy <= n; xy ++) {
		for (int i = 1; i * i <= xy; i ++) if (xy % i == 0) {
			int x = i, y = xy / i;
			check(x, y);
			if (x != y) check(y, x);
		}
	}
	for (int i = 1; i * i <= n; i ++) if (n % i == 0) {
		int y = i, z = n / i;
		if (y > z) swap(y, z);
		ans.push_back({ 0, y, z });
	}
	for (auto [x, y, z] : ans) {
		vector<int> arr{ x, y, z };
		vector<int> p{ 1, 2, 3 };
		do {
			nans.push_back({ arr[p[0] - 1], arr[p[1] - 1], arr[p[2] - 1] });
		} while(next_permutation(p.begin(), p.end()));
	}
	sort(nans.begin(), nans.end());
	nans.erase(unique(nans.begin(), nans.end()), nans.end());
	cout << nans.size() << "\n";
	for (auto [x, y, z] : nans) cout << x << " " << y << " " << z << "\n";
	return 0;
}
0