結果

問題 No.2358 xy+yz+zx=N
ユーザー t98slidert98slider
提出日時 2023-06-23 22:15:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,565 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 182,076 KB
実行使用メモリ 7,480 KB
最終ジャッジ日時 2023-09-14 10:10:16
合計ジャッジ時間 6,472 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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