結果

問題 No.2624 Prediction by Average
ユーザー srjywrdnprkt
提出日時 2024-02-29 12:51:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 194,908 KB
最終ジャッジ日時 2025-02-19 21:59:29
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    //87.500 <= average < 87.501
    //87500 <= 1000*average < 87501
    //87500 <= 1000*s/k < 87501
    //87500k/1000 <= s < 87501k/1000が整数解を持つk
    //k>=1000のとき、必ず存在する
    //87500k <= 1000s < 87501k

    ll T, N, S, ans, x;
    string U;
    cin >> T;
    while(T--){
        cin >> N >> U;
        ans = 0;
        U.erase(remove(U.begin(), U.end(), '.'), U.end());
        S = stoll(U);
        for (int i=1; i<1000; i++){
            x = (S*i+999) / 1000 * 1000;
            if (x < (S+1)*i && i <= N) ans++;
        }
        ans += max(0LL, N-999);
        cout << ans << endl;
    }

    return 0;
}
0