結果

問題 No.1200 お菓子配り-3
ユーザー finefine
提出日時 2020-08-28 21:57:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,186 bytes
コンパイル時間 1,685 ms
コンパイル使用メモリ 162,724 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 22:49:40
合計ジャッジ時間 9,785 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 8 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 56 ms
5,376 KB
testcase_13 AC 56 ms
5,376 KB
testcase_14 AC 57 ms
5,376 KB
testcase_15 AC 58 ms
5,376 KB
testcase_16 AC 55 ms
5,376 KB
testcase_17 AC 202 ms
5,376 KB
testcase_18 AC 286 ms
5,376 KB
testcase_19 AC 69 ms
5,376 KB
testcase_20 AC 551 ms
5,376 KB
testcase_21 AC 559 ms
5,376 KB
testcase_22 AC 658 ms
5,376 KB
testcase_23 AC 553 ms
5,376 KB
testcase_24 AC 552 ms
5,376 KB
testcase_25 AC 552 ms
5,376 KB
testcase_26 AC 555 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 920 ms
5,376 KB
testcase_29 AC 672 ms
5,376 KB
testcase_30 AC 670 ms
5,376 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = int;

constexpr char newl = '\n';

ll solve(ll x, ll y) {    
    // x = ab+c, y = ac+b
    // x + y = (a + 1)(b + c)
    ll sum = x + y;
    ll res = 0;
    for (ll i = 2; i * i <= sum; i++) {
        if (sum % i != 0) continue;
        ll j = sum / i;

        // a + 1 == i, b + c == j
        // (i - 1) c + (j - c) == y
        // (i - 2) c + j == y
        // c == (y - j) / (i - 2)
        if (i > 2 && y > j && (y - j) % (i - 2) == 0) {
            ll a = i - 1;
            ll c = (y - j) / (i - 2);
            ll b = j - c;
            res += (a > 0 && b > 0 && c > 0);
        }

        // b + c == i, a + 1 == j
        // c == (y - i) / (j - 2)
        if (j > 2 && y > i && (y - i) % (j - 2) == 0) {
            ll a = j - 1;
            ll c = (y - i) / (j - 2);
            ll b = i - c;
            res += (a > 0 && b > 0 && c > 0);            
        }
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        cout << solve(x, y) << newl;
    }

    return 0;
}
0