Submission #4501911


Source Code Expand

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/08  Problem: ABC 093 D / Link: http://abc093.contest.atcoder.jp/tasks/abc093_d  ----- */


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

	LL Q; cin >> Q;
	auto f = [](LL A, LL B) {
		if (A == B)return 2 * (A - 1);
		LL upMax = A * B - 1;

		LL L = 1, R = 10LL*INF;
		while (R - L > 1) {
			LL mid = (L + R) / 2;
			LL mulmax = (
				mid & 1 ?
				(mid / 2 + 1)*(mid / 2 + 1)
				:
				(mid / 2)*(mid / 2 + 1)
				);
			if (mulmax > upMax)R = mid;
			else L = mid;

		}

		return L - 1;
	};
	FOR(_, 0, Q) {
		LL A, B; cin >> A >> B;
		LL ans = f(A, B);
		cout << (ans) << "\n";
	}



	return 0;
}

Submission Info

Submission Time
Task D - Worst Case
User Yang33
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1631 Byte
Status AC
Exec Time 1 ms
Memory 256 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 12
Set Name Test Cases
Sample s1.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, s1.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KiB
02.txt AC 1 ms 256 KiB
03.txt AC 1 ms 256 KiB
04.txt AC 1 ms 256 KiB
05.txt AC 1 ms 256 KiB
06.txt AC 1 ms 256 KiB
07.txt AC 1 ms 256 KiB
08.txt AC 1 ms 256 KiB
09.txt AC 1 ms 256 KiB
10.txt AC 1 ms 256 KiB
11.txt AC 1 ms 256 KiB
s1.txt AC 1 ms 256 KiB