QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#847130#5721. Dividing by TwoLaVuna47#AC ✓0ms3752kbC++201.7kb2025-01-07 17:37:062025-01-07 17:37:06

Judging History

你现在查看的是最新测评结果

  • [2025-01-07 17:37:06]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3752kb
  • [2025-01-07 17:37:06]
  • 提交

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

// 103 27
// 104 27
// 52 27
// 26 27
// 27 27
// 100 5
ll B;

// 4 3

ll f(ll A)
{
	if(A <= B) return (B-A);
	
	ll res=1e9;
	if(A%2==0)
	{
		res=min(res, 1+f(A/2));
	}
	else
	{
		res=min(res, 2+f((A+1)/2));
	}
	return res;
}

int solve()
{
	ll A;
	if(!(cin>>A>>B))return 1;
	cout<< f(A)<<'\n';
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1e9;
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3512kb

input:

103 27

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

3 8

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

1010 1010

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

536780502 141579856

output:

7384733

result:

ok single line: '7384733'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

108493886 96306036

output:

42059094

result:

ok single line: '42059094'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

376650637 614573517

output:

237922880

result:

ok single line: '237922880'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

359617991 796927336

output:

437309345

result:

ok single line: '437309345'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

414483268 377437212

output:

170195579

result:

ok single line: '170195579'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

264989209 721686150

output:

456696941

result:

ok single line: '456696941'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

535692831 577823164

output:

42130333

result:

ok single line: '42130333'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

976420008 290057285

output:

45952285

result:

ok single line: '45952285'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

658562524 270258804

output:

105618175

result:

ok single line: '105618175'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

754831094 581446183

output:

204030637

result:

ok single line: '204030637'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

536870913 1

output:

59

result:

ok single line: '59'