結果

問題 No.1626 三角形の構築
ユーザー milanis48663220milanis48663220
提出日時 2021-07-23 22:54:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,181 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 131,812 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-20 15:55:55
合計ジャッジ時間 4,957 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,752 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

vector<ll> facs(ll x){
    vector<ll> ans;
    for(ll i = 1; i*i <= x; i++){
        if(x%i == 0){
            ans.push_back(i);
            if(i*i != x) ans.push_back(x/i);
        }
    }
    sort(ans.begin(), ans.end());
    return ans;
}

ll sq_ll(ll x){
    ll ans = sqrt(x)+0.1;
    if(ans*ans > x) ans--;
    return ans;
}

using T = tuple<ll, ll, ll>;

void solve(){
    ll S, t; cin >> S >> t;
    ll s = S*S*16;
    if(s%t != 0){
        cout << 0 << endl;
        return;
    }
    ll x = s/t;
    vector<ll> v = facs(4*s);
    set<ll> st;
    for(ll a: v){
        for(ll b: v){
            if(x%(a*b) == 0) st.insert(a*b);
        }
    }
    vector<T> ans;
    for(ll p: st){
        if(p >= t) continue;
        if(p%2 != t%2) continue;
        // q+r = l
        // q*r = m
        ll a = (t-p)/2;
        ll l = 2*a;
        ll m = x/p;
        ll D = l*l-4*m;
        if(D < 0) continue; 
        ll sq = sq_ll(D);
        if(sq*sq != D) continue;
        if(l%2 != sq%2) continue;
        if(l <= sq) continue;
        ll q = (l-sq)/2;
        ll r = (l+sq)/2;
        if(q >= p){
            if(t%2 != q%2) continue;
            if(t%2 != r%2) continue;
            ll b = (t-q)/2;
            ll c = (t-r)/2;
            ans.push_back(T(a, b, c));
        }
    }
    cout << ans.size() << endl;
    for(auto [a, b, c]: ans) cout << a << ' ' << b << ' ' << c << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) solve();
}
0