結果

問題 No.2624 Prediction by Average
ユーザー norikamenorikame
提出日時 2024-02-09 23:16:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 4,295 ms
コンパイル使用メモリ 263,288 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-09 23:16:39
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 5 ms
6,676 KB
testcase_02 AC 6 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 7 ms
6,676 KB
testcase_05 AC 7 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const int INF = (int)(1e9);

int main() {
	int t0;
	cin >> t0;
	rep(i0, t0) {
		ll n;
		string s;
		cin >> n >> s;
		int pi = s.find('.'), si = stoi(s.substr(0, pi)) * 1000 + stoi(s.substr(pi+1));
		ll li = 0, ri = n+1;
		while (ri-li > 1) {
			ll ci = li + (ri-li) / 2, lval = si * ci, rval = (si+1) * ci;
			if (rval-lval <= 1000) li = ci;
			else ri = ci;
		}
		ll res = (n+1) - ri;
		rep3(i, 1, ri) if (si*(ll)i/1000 < ((si+1)*(ll)i-1)/1000 || si*(ll)i%1000 == 0) ++res;
		cout << res << endl;
	}
	return 0;
}
0