結果
| 問題 |
No.1626 三角形の構築
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-07-23 22:12:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 959 ms / 2,000 ms |
| コード長 | 1,936 bytes |
| コンパイル時間 | 2,251 ms |
| コンパイル使用メモリ | 196,056 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 11:34:02 |
| 合計ジャッジ時間 | 4,857 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<tuple<int, int, int>> &ans, vector<pair<int, int>> &F, long long s, long long x, long long y, long long z, int p){
int cnt = F.size();
if (p == cnt){
if (x + y + z == s && max({x, y, z}) <= 1000000000){
vector<long long> a = {x, y, z};
sort(a.begin(), a.end());
ans.push_back(make_tuple(a[0], a[1], a[2]));
}
} else {
int b = F[p].first;
int e = F[p].second;
vector<long long> POW(e + 1);
POW[0] = 1;
for (int i = 0; i < e; i++){
POW[i + 1] = POW[i] * b;
}
for (int i = 0; i <= e; i++){
for (int j = 0; j <= e - i; j++){
dfs(ans, F, s, x * POW[i], y * POW[j], z * POW[e - i - j], p + 1);
}
}
}
}
int main(){
int t;
cin >> t;
for (int i = 0; i < t; i++){
long long S, T;
cin >> S >> T;
if (T % 2 != 0){
cout << 0 << endl;
} else if (S * S * 2 % T != 0){
cout << 0 << endl;
} else {
long long s = T / 2;
long long p = S * S * 2 / T;
map<int, int> mp;
for (long long j = 2; j * j <= S; j++){
while (S % j == 0){
mp[j] += 2;
S /= j;
}
}
if (S > 1){
mp[S] += 2;
}
mp[2]++;
for (long long j = 2; j * j <= T; j++){
while (T % j == 0){
mp[j]--;
T /= j;
}
}
if (T > 1){
mp[T]--;
}
vector<pair<int, int>> F;
for (auto P : mp){
if (P.second != 0){
F.push_back(P);
}
}
vector<tuple<int, int, int>> ans;
dfs(ans, F, s, 1, 1, 1, 0);
sort(ans.begin(), ans.end());
ans.erase(unique(ans.begin(), ans.end()), ans.end());
int cnt = ans.size();
cout << cnt << endl;
for (int j = 0; j < cnt; j++){
cout << s - get<0>(ans[j]) << ' ' << s - get<1>(ans[j]) << ' ' << s - get<2>(ans[j]) << endl;
}
}
}
}
SSRS