結果

問題 No.3356 A÷B問題
コンテスト
ユーザー SnowBeenDiding
提出日時 2025-11-14 21:54:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,527 bytes
コンパイル時間 4,892 ms
コンパイル使用メモリ 335,668 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-11-14 21:54:30
合計ジャッジ時間 6,027 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

__int128 f(int k) {
    __int128 x = 1;
    rep(i, 0, k) x *= 10;
    return x;
}

string g(__int128 x) {
    string s;
    while (x) {
        s += (char)('0' + (x % 10));
        x /= 10;
    }
    reverse(s.begin(), s.end());
    return s;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    ll na, nb;
    cin >> na >> nb;
    __int128 a = na, b = nb;
    a *= f(20);
    auto check = [&](__int128 x) {
        if (a >= b * x)
            return 1;
        else
            return 0;
    };
    auto binary = [&]() {
        __int128 ac = -f(30), wa = +f(30);
        __int128 mid = ac + (wa - ac) / 2;
        while (wa - ac > 1) {
            if (check(mid))
                ac = mid;
            else
                wa = mid;
            mid = ac + (wa - ac) / 2;
        }
        return ac;
    };
    auto ans_num = binary();
    if (ans_num == 0) {
        cout << "0\n";
        return 0;
    }
    if (ans_num < 0) {
        cout << '-';
        ans_num *= -1;
    }
    string ans = g(ans_num);
    while (ans.size() < 20) ans = "0" + ans;
    string pre, suf;
    pre = ans;
    while (suf.size() < 20) {
        suf += pre.back();
        pre.pop_back();
    }
    reverse(suf.begin(), suf.end());
    if (pre == "") pre = "0";
    cout << pre << '.' << suf << endl;
}
0