結果

問題 No.2358 xy+yz+zx=N
ユーザー 遭難者遭難者
提出日時 2023-06-05 14:46:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 207,204 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 10:01:23
合計ジャッジ時間 3,308 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ALL(a) a.begin(), a.end()
void solve()
{
    int n;
    cin >> n;
    int nn = n / 3;
    vector<tuple<int, int, int>> ans;
    int x = 0, xx = 0;
    while (xx <= nn)
    {
        const int k = n + xx;
        int yy = x << 1, yyy = yy * yy;
        while (yyy <= k)
        {
            if (yy == 0 || k % yy > 0)
            {
                yyy += (yy++ << 1) | 1;
                continue;
            }
            vector<int> per = {x, yy - x, k / yy - x};
            do
            {
                ans.push_back({per[0], per[1], per[2]});
            } while (next_permutation(ALL(per)));
            yyy += (yy++ << 1) | 1;
        }
        xx += (x++ << 1) | 1;
    }
    cout << ans.size() << '\n';
    for (auto &[x, y, z] : ans)
        cout << x << ' ' << y << ' ' << z << '\n';
    return;
}
int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(13);
    solve();
    return 0;
}
0