結果

問題 No.2358 xy+yz+zx=N
ユーザー 👑 hitonanodehitonanode
提出日時 2023-06-23 23:28:46
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 112,336 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 10:16:11
合計ジャッジ時間 2,439 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
using lint = long long;

int main() {
    int N;
    cin >> N;

    vector<tuple<int, int, int>> ret;
    for (lint lo = 0; lo * lo * 3 <= N; ++lo) {
        for (lint med = lo; lo * med + med * med + med * lo <= N; ++med) {
            if (!med) continue;
            lint rem = N - lo * med;

            if (rem % (lo + med)) continue;

            lint hi = rem / (lo + med);

            ret.emplace_back(lo, med, hi);
            ret.emplace_back(lo, hi, med);
            ret.emplace_back(hi, med, lo);
            ret.emplace_back(hi, lo, med);
            ret.emplace_back(med, hi, lo);
            ret.emplace_back(med, lo, hi);
        }
    }
    sort(ret.begin(), ret.end());
    ret.erase(unique(ret.begin(), ret.end()), ret.end());

    cout << ret.size() << '\n';
    for (auto [x, y, z] : ret) cout << x << ' ' << y << ' ' << z << '\n';
}
0