結果

問題 No.1626 三角形の構築
ユーザー maine_honzukimaine_honzuki
提出日時 2021-07-23 21:55:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,956 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 217,492 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-02 15:44:22
合計ジャッジ時間 11,672 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,536 KB
testcase_01 AC 260 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 207 ms
4,384 KB
testcase_08 AC 326 ms
4,380 KB
testcase_09 AC 459 ms
4,380 KB
testcase_10 AC 247 ms
4,376 KB
testcase_11 AC 376 ms
4,380 KB
testcase_12 AC 84 ms
4,376 KB
testcase_13 AC 113 ms
4,376 KB
testcase_14 AC 228 ms
4,380 KB
testcase_15 AC 122 ms
4,380 KB
testcase_16 AC 255 ms
4,376 KB
testcase_17 AC 225 ms
4,376 KB
testcase_18 AC 154 ms
4,376 KB
testcase_19 AC 259 ms
4,376 KB
testcase_20 AC 329 ms
4,380 KB
testcase_21 AC 283 ms
4,376 KB
testcase_22 AC 485 ms
4,380 KB
testcase_23 AC 312 ms
4,380 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> ret;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ll num = 0;
            while (n % i == 0) {
                num++;
                n /= i;
            }
            ret.push_back({i, num});
        }
    }
    if (n != 1)
        ret.push_back({n, 1});
    return ret;
}

ll S, T;
vector<pair<ll, ll>> V;
vector<vector<ll>> Pow;
set<vector<ll>> ans;

void maine(vector<ll> Len, int idx) {
    if (idx == V.size()) {
        for (auto&& l : Len) {
            l = T - l;
            if (l % 2 == 1 || l <= 0)
                return;
            l /= 2;
        }
        sort(begin(Len), end(Len));
        if (Len[0] + Len[1] > Len[2] && Len[1] + Len[2] > Len[0] && Len[2] + Len[0] > Len[1] && Len[0] + Len[1] + Len[2] == T)
            ans.insert(Len);
    } else {
        auto [n, m] = V[idx];
        for (int i = 0; i <= m; i++) {
            for (int j = 0; j <= m - i; j++) {
                int k = m - i - j;
                auto nxt = Len;
                nxt[0] *= Pow[idx][i];
                nxt[1] *= Pow[idx][j];
                nxt[2] *= Pow[idx][k];
                maine(nxt, idx + 1);
            }
        }
    }
}

void solve() {
    ans.clear();
    Pow.clear();
    cin >> S >> T;
    if ((16 * S * S) % T) {
        cout << 0 << endl;
        return;
    }
    V = prime_factorize(16 * S * S / T);
    for (auto&& [n, m] : V) {
        vector<ll> book(1, 1);
        for (int i = 0; i < m; i++) {
            book.emplace_back(n * book.back());
        }
        Pow.emplace_back(book);
    }
    maine({1, 1, 1}, 0);
    cout << ans.size() << endl;
    for (auto&& e : ans) {
        for (int i = 0; i < 3; i++) {
            cout << e[i] << " \n"[i == 2];
        }
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
0