結果

問題 No.2358 xy+yz+zx=N
ユーザー twooimp2twooimp2
提出日時 2023-11-22 18:56:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 210,868 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-22 18:56:57
合計ジャッジ時間 4,329 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 121 ms
6,676 KB
testcase_09 AC 129 ms
6,676 KB
testcase_10 AC 81 ms
6,676 KB
testcase_11 AC 88 ms
6,676 KB
testcase_12 AC 57 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  ll n;
  cin>>n;
  set<T> ans;
  for(ll z=0;z*z<=n;z++){
    for(ll y=0;y<=z;y++){
      if(y==0&&z==0){
        continue;
      }
      if((n-y*z)%(y+z)==0){
        ll x=(n-y*z)/(y+z);
        if(x*y+y*z+z*x==n){
          if(x==y&&y==z){
            ans.insert(T(x,y,z));
          }else if(x==y){
            ans.insert(T(x,y,z));
            ans.insert(T(x,z,y));
            ans.insert(T(z,x,y));
          }else if(y==z){
            ans.insert(T(x,y,z));
            ans.insert(T(y,x,z));
            ans.insert(T(y,z,x));
          }else{
            ans.insert(T(x,y,z));
            ans.insert(T(x,z,y));
            ans.insert(T(y,x,z));
            ans.insert(T(y,z,x));
            ans.insert(T(z,x,y));
            ans.insert(T(z,y,x));
          }
        }
      }
    }
  }
  cout<<ans.size()<<endl;
  auto itr=ans.begin();
  while(itr!=ans.end()){
    cout<<get<0>(*itr)<<" "<<get<1>(*itr)<<" "<<get<2>(*itr)<<endl;
    itr++;
  }
}
0