結果

問題 No.1626 三角形の構築
ユーザー milanis48663220milanis48663220
提出日時 2021-07-23 23:05:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,471 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 139,052 KB
実行使用メモリ 31,984 KB
最終ジャッジ日時 2023-08-02 15:54:32
合計ジャッジ時間 7,969 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 54 ms
4,884 KB
testcase_02 AC 1 ms
4,380 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,376 KB
testcase_07 AC 41 ms
4,704 KB
testcase_08 AC 68 ms
4,824 KB
testcase_09 AC 90 ms
6,328 KB
testcase_10 AC 59 ms
5,236 KB
testcase_11 AC 70 ms
4,856 KB
testcase_12 AC 23 ms
4,380 KB
testcase_13 AC 24 ms
4,380 KB
testcase_14 AC 33 ms
4,920 KB
testcase_15 AC 33 ms
4,492 KB
testcase_16 AC 61 ms
6,236 KB
testcase_17 AC 43 ms
4,600 KB
testcase_18 AC 32 ms
4,376 KB
testcase_19 AC 53 ms
5,124 KB
testcase_20 AC 58 ms
4,928 KB
testcase_21 AC 51 ms
4,944 KB
testcase_22 AC 90 ms
6,184 KB
testcase_23 AC 66 ms
4,912 KB
testcase_24 AC 1,147 ms
29,788 KB
testcase_25 TLE -
testcase_26 AC 112 ms
21,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#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);
    assert(v.size() <= 2000);
    vector<ll> st;
    for(int i = 0; i < v.size(); i++){
        for(ll j = i; j < v.size(); j++){
            ll p = v[i]*v[j];
            if(x%p == 0) st.push_back(p);
        }
    }
    vector<T> ans;
    sort(st.begin(), st.end());
    ll pre = -1;
    for(ll p: st){
        if(pre == p) continue;
        pre = p;
        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