Submission #66668797


Source Code Expand

#if __has_include("pch.hpp")
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <atcoder/segtree>
#endif
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937_64 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//ld rand(ld a, ld b) {uniform_real_distribution<ld> uni(a, b); return uni(mt_rand);}
//const ld PI=3.141592653589793238462643383279;
const int mxN=1e6+50000;
const int mod=1e9+7;
const int mxlogN=19;
const ll inf=1e18;
const int iinf=1e9;
const int K=60;
pair<ll,ll> solve(ll a, ll b, ll c, ll d)
{
    ll f=a/b;
    if(f)
    {
        auto [p,q]=solve(a-b*f,b,c-d*f,d);
        p+=q*f;
        return {p,q};
    }
    if(c>d) return {1,1};
    auto [p,q]=solve(d,c,b,a);
    return {q,p};
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t; cin >> t;
    while(t--)
    {
        ll a,b,c,d; cin >> a >> b >> c >> d;
        cout << solve(a,b,c,d).second << "\n";
    }
}

Submission Info

Submission Time
Task G - A/B < p/q < C/D
User toniskrijelj
Language C++ 20 (gcc 12.2)
Score 625
Code Size 1282 Byte
Status AC
Exec Time 412 ms
Memory 4432 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 625 / 625
Status
AC × 1
AC × 35
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3460 KiB
01_handmade_00.txt AC 9 ms 3452 KiB
01_handmade_01.txt AC 1 ms 3540 KiB
01_handmade_02.txt AC 412 ms 4196 KiB
01_handmade_03.txt AC 366 ms 4220 KiB
01_handmade_04.txt AC 360 ms 4152 KiB
01_handmade_05.txt AC 157 ms 3480 KiB
01_handmade_06.txt AC 61 ms 4432 KiB
01_handmade_07.txt AC 136 ms 3516 KiB
01_handmade_08.txt AC 138 ms 3388 KiB
01_handmade_09.txt AC 60 ms 4188 KiB
01_handmade_10.txt AC 58 ms 4276 KiB
01_handmade_11.txt AC 60 ms 4296 KiB
01_handmade_12.txt AC 58 ms 4228 KiB
01_handmade_13.txt AC 60 ms 4220 KiB
01_handmade_14.txt AC 57 ms 4212 KiB
01_handmade_15.txt AC 55 ms 3992 KiB
02_random_00.txt AC 150 ms 3456 KiB
02_random_01.txt AC 151 ms 3488 KiB
02_random_02.txt AC 151 ms 3516 KiB
02_random_03.txt AC 152 ms 3500 KiB
02_random_04.txt AC 159 ms 3544 KiB
02_random_05.txt AC 157 ms 3496 KiB
02_random_06.txt AC 138 ms 3496 KiB
02_random_07.txt AC 138 ms 3488 KiB
02_random_08.txt AC 125 ms 3392 KiB
02_random_09.txt AC 124 ms 3488 KiB
02_random_10.txt AC 146 ms 3488 KiB
02_random_11.txt AC 146 ms 3488 KiB
02_random_12.txt AC 148 ms 3480 KiB
02_random_13.txt AC 148 ms 3452 KiB
02_random_14.txt AC 146 ms 3500 KiB
02_random_15.txt AC 145 ms 3480 KiB
02_random_16.txt AC 72 ms 3456 KiB
02_random_17.txt AC 71 ms 3492 KiB