Source Code
#include<bits/stdc++.h>
#define ll long long 

using namespace std;
ll MOD = 998244353 ;
ll bigMod(ll x,ll y){
    if (y == 0)return 1;
    if (y == 1)return x;
    ll res = bigMod(x , y / 2LL);
    res *= res;
    res %= MOD;
    if (y % 2){
        res *= x;
        res %= MOD;
    }
    return res;
}
ll fac[1000005];
ll choose(ll x,ll y){
    if (x == y)return 1;
    if (y > x)return 0;
    if (y == 0)return 1;
    ll up = fac[x];
    ll down = fac[y] * fac[x-y];
    down %= MOD;
    ll ret = up * bigMod(down , MOD - 2);
    ret %= MOD;
    return ret;
}

int t;
ll n , k , m;
int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> k >> m;
    bool ev = 0;
    int cnt = 0;
    int cnt2 = 0;
    for (int i=0;i<n;i++){
        ll x , y;
        cin >> x >> y;
        if (x % 2 == 1){
            ev = !ev;
        }
        if ((x%2) != (y%2)){
            cnt++;
        }
        else {
            cnt2++;
        }
    }
    if (cnt == 0){
        if (ev == m){
            cout << 1 << endl;
        }
        else {
            cout << 2 << endl;
        }
        return 0;
    }
    if (k % 2 == 0){
        if (cnt > 0 && cnt2 > 0){
            cout << 2 << endl;
            return 0;
        }
        else {
            if (ev == m)cout << 1 << endl;
            else cout << 2 << endl;
            return 0;
        }
    }
    else {
        if (cnt > 0 && cnt2 > 0){
            cout << 1 << endl;
            return 0;
        }
        else {
            if (cnt > 0){
                if (ev == m)cout << 2 << endl;
                else cout << 1 << endl;
            }
            else if (cnt2 > 0){
                if (ev == m)cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
    }
    return 0;
}
Copy
Cliffs of Dover Khaled97ha
GNU G++17
122 ms
876 KB
Accepted