1260C - Infinite Fence - CodeForces Solution


greedy math number theory *1700

Please click on ads to support us..

Python Code:

n = int(input())
from math import gcd, ceil
for _ in range(n):
    r, b, k = map(int, input().split())
    g = gcd(r, b)
    r /= g
    b /= g
    if r == b:
        print("OBEY")
        continue
    if r > b:
        r, b = b, r
    fit = ceil((b-1) / r)
    if fit < k:
        print("OBEY")
    else:
        print("REBEL")

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, in) for (ll i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (ll i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define pb push_back
#define f(v) v.begin(),v.end() 

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef unordered_map<int, int> umap_ii;
typedef map<int, int> mii;
ll modAdd( ll a , ll b ){return ( a%MOD + b%MOD ) % MOD;}
ll modSubtract( ll a , ll b ){return ( ( a%MOD - b%MOD ) + MOD )%MOD;}
ll modProduct( ll a , ll b ){return ( a%MOD * b%MOD ) % MOD;}
ll binPow( ll a , ll b ){if(b==0)return 1; ll res = binPow(a,b/2);if(b&1ll)res=res*a;return res;}
ll inv(ll x){ return binPow(x, MOD-2);}
ll divide(ll x, ll y){return modProduct(x, inv(y));}
void printVector(vector<long long> v) {for(long long i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;}
void printMatrix(vector<vector<ll>> v) {for(ll i=0; i<v.size(); i++){for(ll j=0; j<v[i].size(); j++) cout<<v[i][j]<<" "; cout<<endl;}}
void printPairVector(vector<pair<ll,ll>> v){for(ll i=0; i<v.size(); i++) cout<<v[i].first<<","<<v[i].second<<" "; cout<<endl;}
void printGraph(vvl& adj, ll n){for(ll i=1; i<=n; i++){cout<<i<<" -> ";for(ll j=0; j<adj[i].size(); j++){cout<<adj[i][j]<<" ";}cout<<endl;} cout<<endl;}
void inputUndirectedGraph(vvl& adj, ll n, ll m){for(ll i=0; i<m; i++){ll u,v; cin>>u>>v; adj[u].push_back(v);adj[v].push_back(u);}}
void inputDirectedGraph(vvl& adj, ll n, ll m){for(ll i=0; i<m; i++){ll u,v; cin>>u>>v; adj[u].push_back(v);}}
void inputVector(vl& v){for(ll i=0; i<v.size(); i++){cin>>v[i];}}
ll spacesplit(string s){ll i=0; while(i<s.length() && s[i]!=' '){i++;} return i;}
 
 
ll maxn;
vl segt;
vb marked;
void push(int v) {
if (marked[v]) {
segt[v*2] = segt[v*2+1] = segt[v];
marked[v*2] = marked[v*2+1] = true;
marked[v] = false;
}
}
 
void update(ll v, ll tl, ll tr, ll l, ll r, ll new_val) {
if (l > r)
return;
if (l == tl && tr == r) {
segt[v] = new_val;
marked[v] = true;
} else {
push(v);
ll tm = (tl + tr) / 2;
update(v*2, tl, tm, l, min(r, tm), new_val);
update(v*2+1, tm+1, tr, max(l, tm+1), r, new_val);
}
}
 
 
ll get(ll v, ll tl, ll tr, ll pos) {
if (tl == tr) {
return segt[v];
}
push(v);
ll tm = (tl + tr) / 2;
if (pos <= tm)
return get(v*2, tl, tm, pos);
else
return get(v*2+1, tm+1, tr, pos);
}
 
void build(ll v, ll tl, ll tr, vl& a)
{
    if(tl==tr)
    {
        segt[v] = a[tl];
        return;
    }
    ll tm = (tl+tr)>>1;
    build(2*v, tl, tm, a);
    build(2*v+1, tm+1, tr, a);
    segt[v] = min(segt[2*v], segt[2*v+1]);
}
 
ll query(ll v, ll tl, ll tr, ll l, ll r)
{
    if(l>r)
        return LLONG_MAX;
    if(l==tl && r==tr)
        return segt[v];
    ll tm = (tl+tr)>>1;
    return min(query(2*v, tl, tm, l, min(r, tm)), query(2*v+1, tm+1, tr, max(l, tm+1), r));
}
 
void update(ll pos, ll x, ll v, ll tl, ll tr)
{
    if(tl==tr)
    {
        segt[v] = x;
        return;
    }
    ll tm = (tl+tr)>>1;
    if(pos <= tm)
    {
        update(pos, x, 2*v, tl, tm);
    }
    else
    {
        update(pos, x, 2*v+1, tm+1, tr);
    }
    segt[v] = min(segt[2*v], segt[2*v+1]);
}

ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll r, b, k;
        cin>>r>>b>>k;

        if(r>b)
            swap(r, b);
        ll g = __gcd(r, b);
        r /= g;
        b /= g;
        // int sr = 1, sb = -1;

        // ll x, y;
        // gcd(r, -b, x, y);

        // ll pos = b*y;
        
        if((k-1)*r+1>=b)
            cout<<"OBEY"<<endl;
        else
            cout<<"REBEL"<<endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks