結果

問題 No.1200 お菓子配り-3
ユーザー lorent_kyoprolorent_kyopro
提出日時 2020-08-29 00:24:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,182 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 207,836 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 00:53:40
合計ジャッジ時間 42,903 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 6 ms
6,940 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 33 ms
6,940 KB
testcase_08 AC 34 ms
6,944 KB
testcase_09 AC 31 ms
6,944 KB
testcase_10 AC 32 ms
6,944 KB
testcase_11 AC 32 ms
6,944 KB
testcase_12 AC 295 ms
6,940 KB
testcase_13 AC 302 ms
6,940 KB
testcase_14 AC 302 ms
6,940 KB
testcase_15 AC 305 ms
6,944 KB
testcase_16 AC 300 ms
6,940 KB
testcase_17 AC 1,089 ms
6,944 KB
testcase_18 AC 1,566 ms
6,940 KB
testcase_19 AC 359 ms
6,944 KB
testcase_20 AC 3,009 ms
6,944 KB
testcase_21 AC 3,011 ms
6,944 KB
testcase_22 AC 3,570 ms
6,944 KB
testcase_23 AC 3,007 ms
6,940 KB
testcase_24 AC 2,991 ms
6,944 KB
testcase_25 AC 2,994 ms
6,944 KB
testcase_26 AC 3,004 ms
6,940 KB
testcase_27 WA -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;

template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

vector<long long> enum_div(long long n) {
    vector<long long> res;
    for (long long i = 1; i*i <= n; i++) {
        if (n%i) continue;
        res.push_back(i);
        if (i*i != n) res.push_back(n/i);
    }
    sort(res.begin(), res.end());
    return res;
}

void solve() {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    int sum = x + y;
    int diff = y - x;
    auto sum_div = enum_div(sum);
    auto diff_div = enum_div(diff);
    int n = sum_div.size(), m = diff_div.size();
    int idx = 0;
    int cnt = 0;
    rep(i, n-1) {
        while (idx < m && diff_div[idx] < sum_div[i] - 2) idx++;
        if (idx == m) break;
        if (diff_div[idx] == sum_div[i] - 2) {
            int p = sum / sum_div[i], q = diff / diff_div[idx];
            if (p % 2 != q % 2 or p - q < 0) continue;
            int b = (p + q) / 2, c = (p - q) / 2;
            if (b <= x && c <= x) cnt++;
        }
    }
    cout << cnt << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}
0