1583C - Omkar and Determination - CodeForces Solution


data structures dp *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define sz(x)(ll) x.size()
#define g_max(x, y) x = max(x, y)
#define g_min(x, y) x = min(x, y)
#define rsz(a, n) a.resize(n)
#define ass(a, n) a.assign(n, 0)
#define YES() cout << "YES\n"
#define Yes cout << "Yes\n"
#define NO() cout << "NO\n"
#define No() cout << "No\n"
#define n_line() cout << "\n"

using namespace std;

using ll = long long;
using ld = long double;

using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using stkll = stack<ll>;
using qll = queue<ll>;
using dqll = deque<ll>;
using sll = set<ll>;
using sc = set<char>;
using msll = multiset<ll>;
using mll = map<ll, ll>;

using vsll = vector<sll>;

using pcll = pair<char, ll>;

template<class T>
vector<T> operator+(vector<T> a, vector<T> b) {
    a.insert(a.end(), b.begin(), b.end());
    return a;
}

pll operator+(pll a, pll b) {
    pll ans = {a.first + b.first, a.second + b.second};
    return ans;
}

template<class A, class B>
ostream &operator<<(ostream &os,
                    const pair<A, B> &p) {
    os << p.first << " " << p.second;
    return os;
}

template<class A, class B>
istream &operator>>(istream &is, pair<A, B> &p) {
    is >> p.first >> p.second;
    return is;
}

template<class T>
ostream &operator<<(ostream &os,
                    const vector<T> &vec) {
    for (auto &x: vec) {
        os << x << " ";
    }

    return os;
}

template<class T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &x: vec) {
        is >> x;
    }

    return is;
}


template<class T>
ostream &operator<<(ostream &os,
                    const set<T> &vec) {
    for (auto &x: vec) {
        os << x << " ";
    }

    return os;
}

template<class A, class B>
ostream &operator<<(ostream &os,
                    const map<A, B> d) {
    for (auto &x: d) {
        os << "(" << x.first << " " << x.second << ") ";
    }

    return os;
}

template<class A>
void read_arr(A a[], ll from, ll to) {
    for (ll i = from; i <= to; i++) {
        cin >> a[i];
    }
}

template<class A>
void print_arr(A a[], ll from, ll to) {
    for (ll i = from; i <= to; i++) {
        cout << a[i] << " ";
    }
    cout << "\n";
}

template<class A>
void set_arr(A a[], A val, ll from, ll to) {
    for (ll i = from; i <= to; i++) {
        a[i] = val;
    }
}

ll dr[] = {0, 1, 0, -1}, dc[] = {-1, 0, 1, 0};

//ll dr[] = {1, 0}, dc[] = {0, 1};

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll M = 13010;

struct Dsu {
    ll n;
    vll par;

    void init(ll n_sz) {
        n = n_sz;
        par.assign(n, 0);

        for (ll i = 0; i < n; i++) {
            par[i] = i;
        }
    }

    ll find_st(ll v) {
        return (par[v] == v) ? par[v] : par[v] = find_st(par[v]);
    }

    ll union_st(ll u, ll v) {
        u = find_st(u), v = find_st(v);

        if (u == v) {
            return 0;
        }

        par[v] = u;
        return 1;
    }
};


void memset64(ll dest[], ll val, ll sz) {
    for (ll i = 0; i < sz; i++) {
        dest[i] = val;
    }
}


void print(ll a[], ll from, ll to) {
    for (ll i = from; i <= to; i++) {
        cout << a[i] << " ";
    }

    cout << "\n";
}


ll gcd_extended(ll a, ll b, ll *x, ll *y) {
    if (a == 0) {
        *x = 0LL, *y = 1LL;
        return b;
    }

    ll x1, y1;
    ll g = gcd_extended(b % a, a, &x1, &y1);
    *x = y1 - (b / a) * x1;
    *y = x1;

    return g;
}

ll mod_pow(ll p, ll n, ll mod = MOD) {
    ll res = 1;

    while (n) {
        if (n & 1) {
            res = (res * p) % mod;
        }

        p = (p * p) % mod;
        n >>= 1;
    }

    return res;
}

ll mod_inverse(ll b, ll mod = MOD) {
    ll x, y;
    ll g = gcd_extended(b, mod, &x, &y);

    if (g != 1) {
        return -1;
    }

    return mod_pow(b, mod - 2, mod);

}

ll mod_add(ll a, ll b, ll mod = MOD) {
    return (a + b) % mod;
}

ll mod_sub(ll a, ll b, ll mod = MOD) {
    return (a - b + mod) % mod;
}

ll mod_mul(ll a, ll b, ll mod = MOD) {
    return ((a % mod) * (b % mod)) % mod;
}

ll mod_div(ll a, ll b, ll mod = MOD) {
    a %= mod;
    ll inv = mod_inverse(b, mod) % mod;
    if (inv == -1) {
        return -1;
    }

    return (a * inv) % mod;
}


ll mod_fact(ll n) {
    if (n < 0) {
        return 0;
    }

    ll ans = 1;
    for (ll i = 2; i <= n; i++) {
        ans *= i;
        ans %= MOD;
    }

    return ans;

}

ll mod_sigma(ll x, ll mod = MOD) {
    ll ans = 1;
    ans = (ans * x) % mod;
    ans = (ans * (x + 1)) % mod;
    ans = mod_div(ans, 2) % mod;
    return ans;
}

mll factorize(ll x) {
    mll dict;
    ll tmp = x;
    while (x % 2 == 0) {
        dict[2]++;
        x /= 2;
    }

    for (ll i = 3; i * i <= tmp; i++) {
        while (x % i == 0) {
            x /= i;
            dict[i]++;
        }
    }

    if (x > 1) {
        dict[x]++;
    }

    return dict;
};

ll is_palindrome(string &str) {
    string rev = str;
    reverse(all(str));
    return rev == str;
}

struct A {
    ll fr, to, val;

    bool operator<(const A &o) const {
        if (fr == o.fr) {
            return to < o.to;
        }

        return fr < o.fr;
    }
};

const ll N = 1e6 + 100;

ll n, m, k, q;
ll a[N], b[N], c[N];
//vvll grid;
string s, s1, s2;

vvll grid;
ll num[N];

void init() {
}

ll get_ans() {
}


void single(ll t_id = 0) {
    cin >> n >> m;
    grid.assign(n, vll(m, 0));

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < m; j++) {
            char ch;
            cin >> ch;
            grid[i][j] = (ch == 'X');
        }
    }

    memset64(num, 0, m + 10);
    ll val = 0;

    for (ll j = 0; j < m - 1; j++) {
        for (ll i = 1; i < n; i++) {
            if (grid[i][j] == 1 && grid[i - 1][j + 1] == 1) {
                val++;
            }
        }

        num[j + 1] = val;
    }

    cin >> q;
    while (q--) {
        ll u, v;
        cin >> u >> v;
        if (num[u - 1] - num[v - 1]) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }


}

void multiple() {
    init();

    ll t;
    cin >> t;

    for (ll i = 0; i < t; i++) {
        single(i);
    }

}

//#endif

#if 0

void multiple() {
    while (cin >> n >> m) {
        if (n == 0 && m == 0) {
            break;
        }

        single();
    }

#endif

int main(int argc, char *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

//    freopen("../input.txt", "r", stdin);
//    multiple();
    single();




    return 0;


};





Comments

Submit
0 Comments
More Questions

1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1
363B - Fence
991B - Getting an A
246A - Buggy Sorting
884A - Book Reading