結果
| 問題 |
No.2358 xy+yz+zx=N
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-23 22:15:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,565 bytes |
| コンパイル時間 | 1,965 ms |
| コンパイル使用メモリ | 185,312 KB |
| 実行使用メモリ | 13,756 KB |
| 最終ジャッジ日時 | 2024-07-01 17:35:05 |
| 合計ジャッジ時間 | 6,227 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 2 WA * 3 TLE * 1 -- * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> istream& operator >> (istream& is, vector<T>& vec) {
for(T& x : vec) is >> x;
return is;
}
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
if(vec.empty()) return os;
os << vec[0];
for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
return os;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<tuple<ll, ll, ll>> ans;
int n;
cin >> n;
auto f = [&](ll x, ll y){
ll ng = -1, ok = n;
while(ng + 1 < ok){
ll mid = (ok + ng) / 2;
ll v = x * y + y * mid + mid * x;
(n <= v ? ok : ng) = mid;
}
return ok;
};
vector<int> a = {0, 1, n};
do{
ans.emplace_back(a[0], a[1], a[2]);
}while(next_permutation(a.begin(), a.end()));
for(int x = 1; x <= n; x++){
for(int y = x; x * y <= n; y++){
int z = f(x, y);
ll v = x * y + y * x + x * x;
if(v == n){
a = {x, y, z};
sort(a.begin(), a.end());
do{
ans.emplace_back(a[0], a[1], a[2]);
}while(next_permutation(a.begin(), a.end()));
}
}
}
cout << ans.size() << '\n';
sort(ans.begin(), ans.end());
ans.erase(unique(ans.begin(), ans.end()), ans.end());
for(auto &&tup : ans){
int A, B, C;
tie(A, B, C) = tup;
cout << A << " " << B << " " << C << '\n';
}
}