1776L - Controllers - CodeForces Solution


binary search math

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> pii;
typedef vector<lli> vi;

#define endl "\n"
#define fi first
#define si second
#define pb push_back
#define sz(s) lli(s.size())
#define all(s) begin(s), end(s)
#define print(s) cout<<s<<endl
#define fore(i,a,b) for(lli i = (a), TT=(b); i<TT; ++i)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//---------------------------------
//---------------------------------
const lli MOD = 1e9+7;
//---------------------------------
lli mcd(lli a, lli b) {return b ? mcd(b, a%b) : a;}

lli pos, neg;
lli x, n, a, b;
set<pii> answ;

int main(){_

    cin>>x;
    fore(i,0,x){
        char aux;
        cin>>aux;
        if(aux=='+') pos++;
        else neg++;
    }
    while(pos > 0 && neg > 0){
        lli aux = mcd(pos,neg);
        answ.insert({max(pos, neg)/aux, min(pos,neg)/aux});
        pos--;
        neg--;
    }
    cin>>n;
    while(n--){
        cin>>a>>b;
        lli aux = mcd(a,b);
        if( answ.count({max(a,b)/aux, min(a,b)/aux}) || answ.count({1,1}))
            print("YES");
        else print("NO");
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

38E - Let's Go Rolling
171G - Mysterious numbers - 2
1183C - Computer Game
400C - Inna and Huge Candy Matrix
417A - Elimination
222A - Shooshuns and Sequence
1736A - Make A Equal to B
1736B - Playing with GCD
887C - Solution for Cube
1737C - Ela and Crickets
1741C - Minimize the Thickness
1741A - Compare T-Shirt Sizes
1741D - Masha and a Beautiful Tree
109B - Lucky Probability
1741B - Funny Permutation
1741E - Sending a Sequence Over the Network
344B - Simple Molecules
370A - Rook Bishop and King
546E - Soldier and Traveling
1741G - Kirill and Company
1200B - Block Adventure
1088B - Ehab and subtraction
1270B - Interesting Subarray
478C - Table Decorations
1304C - Air Conditioner
1311C - Perform the Combo
1519C - Berland Regional
361A - Levko and Table
5E - Bindian Signalizing
687A - NP-Hard Problem