結果

問題 No.1626 三角形の構築
ユーザー SSRSSSRS
提出日時 2021-07-23 22:12:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 866 ms / 2,000 ms
コード長 1,936 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 190,620 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 15:50:38
合計ジャッジ時間 4,402 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 25 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 16 ms
6,944 KB
testcase_08 AC 30 ms
6,940 KB
testcase_09 AC 44 ms
6,944 KB
testcase_10 AC 25 ms
6,944 KB
testcase_11 AC 38 ms
6,944 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 11 ms
6,940 KB
testcase_14 AC 25 ms
6,940 KB
testcase_15 AC 9 ms
6,940 KB
testcase_16 AC 27 ms
6,940 KB
testcase_17 AC 21 ms
6,944 KB
testcase_18 AC 13 ms
6,940 KB
testcase_19 AC 24 ms
6,944 KB
testcase_20 AC 37 ms
6,944 KB
testcase_21 AC 32 ms
6,944 KB
testcase_22 AC 48 ms
6,944 KB
testcase_23 AC 31 ms
6,940 KB
testcase_24 AC 866 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 6 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
      }
    }
  }
}
0