1841A - Game with Board - CodeForces Solution


games

Please click on ads to support us..

C++ Code:

//jay Shree Krishna
//har har mahadev

//a%c=b%c
//(b-a)%c=0
//b-a is multiple of c
// The required number of swaps of adjacent elements to sort a permutation is exactly the number of inversions in it
#pragma GCC optimize("O3,unroll-loops","Ofast")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vpll vector<pair<ll,ll>>
#define ull unsigned long long int
#define vll vector<ll>
#define vii vector<int>
#define vcc vector<char>
#define vdd vector<double>
#define vvll vector<vector<ll>>
#define vvii vector<vector<int>>
#define vvcc vector<vector<char>>
#define vvdd vector<vector<double>>
#define rep(i,a,b) for(i=a;i<=b;i++)
#define repr(i,a,b) for(i=a;i>=b;i--)
#define all(v) v.begin() , v.end()
#define rall(v) v.rbegin(),v.rend()
#define ff first
#define ss second
#define pb push_back
#define rev_sort(v) sort(all(v),greater<ll>())
typedef unsigned long long int ulli;
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for (auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for (auto &x : a) out << x << ' '; return out;};

template<typename T1, typename T2> ostream& operator<<(ostream& out, const p<T1, T2>& x) {return out << x.ff << ' ' << x.ss;}
template<typename T1, typename T2> istream& operator>>(istream& in, p<T1, T2>& x) {return in >> x.ff >> x.ss;}

long long int mod =  998244353;

ll powermod(ll a, ll b, ll m)
{
    if (b == 0) return 1;
    ull k = powermod(a, b / 2, m);
    k = k * k;
    k %= m;
    if (b & 1) k = (k * a) % m;
    return k;
}
ll inverse(ll b, ll mod) {
    return powermod(b, mod - 2, mod);
}
// nCr with modulus

// ll factorial(ll n, ll r){
//     if(r==0||r==n) return 1;

//     // dp[n][r]=
//     return (factorial (n-1,r,dp)%mod + factorial (n-1,r-1,dp)%mod)%mod;

// }
ll sqrtf (ll x) {
    ll ans = 0;
    for (ll k = 1LL << 30; k != 0; k /= 2) {
        if ((ans + k) * (ans + k) <= x) {
            ans += k;
        }
    }
    return ans;
}

// ll kadane( vll arr, ll n) {

//     ll max_end = 0;
//     ll mx = LLONG_MIN;

//     for (ll i = 0; i < n; i++) {
//         max_end += arr[i];
//         if (mx < max_end) {

//             mx = max_end;
//         }
//         if (max_end < 0) {

//             max_end = 0;
//         }
//     }
//     return mx;
// }

void bits(ll n, vll&v) {
    ll k = 0;
    while (n > 0) {
        v[k++] = n % 2;
        n /= 2;
    }
}
// Prime test for large numbers

bool isPrime(ull n, int iter = 10)
{
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 0; i < iter; i++)
    {
        ull a = 2 + rand() % (n - 3);
        if (powermod(a, n - 1, n) != 1) return false;
    }
    return true;
}
bool isval(int i, int j, int n, int m) {
    if (i < 0 || j < 0 || i >= n || j >= m) return false;
    return true;
}
ll SOP(ll n, ll k, vll &v) {
    ll dp[k + 1][n + 1];
    ll sum = 1, prev_sum = 1;
    memset(dp, 0, sizeof(dp));
    for (ll i = 1; i <= k; i++) {
        prev_sum = sum;
        sum = 0;
        for (int j = 1; j <= (n - i + 1); j++) {
            dp[i][j] = (v[j - 1] * (prev_sum - dp[i - 1][j])) % mod;
            if (dp[i][j] < 0 ) dp[i][j] += mod;
            prev_sum -= (dp[i - 1][j]) % mod;
            if (prev_sum < 0) prev_sum += mod;
            sum += (dp[i][j]) % mod;
            if (sum < 0) sum += mod;
        }
    }
    return sum;
}
// const ll N = 3e5;
// vll prime(N + 1, -1);
// void sieve(ll n)
// {
//     // for (ll i = 0; i <= n; i++) prime[i] = -1;

//     ll m = sqrt(n);
//     vll ans;
//     for (ll p = 2; p <= m; p++)
//     {

//         //
//         if (prime[p] == -1)
//         {

//             for (ll i = p * 2 ; i <= n; i += p)
//                 if (prime[i] == -1) prime[i] = p;

//         }
//     }

//     return  ;

// }
ll findLowerBound(vector<pair<ll, ll> >& arr,
                  pair<ll, ll>& p1)
{
    // Given iterator points to the
    // lower_bound() of given pair
    auto low = upper_bound(arr.begin(), arr.end(), p1);

    return low - arr.begin();
}
// ll maxvec(vll &v) {
//     ll mx  = LLONG_MIN;
//     ll i;
//     rep(i, 0, v.size() - 1) mx = max(v[i], mx);
//     return mx;
// }
// ll minvec(vll &v) {
//     ll mn  = LLONG_MAX;
//     ll i;
//     rep(i, 0, v.size() - 1) mn = min(v[i], mn);
//     return mn;
// }
ll sumvec(vll &v) {
    ll sum = 0;
    ll i;
    rep(i, 0, v.size() - 1) sum += v[i];
    return sum;
}
ll func(ll i, ll j) {
    if (i % j == 0) return i / j;
    return (i / j) + 1;
}
// double dp[1 << 20];
double helper(ll num, ll n, ll j, vvdd prob) {
    ll curr = __builtin_popcount(num);
    ll den = (curr * (curr - 1)) / 2;
    double ans = 0;

    for (ll k = 0; k < n; k++) {
        if ((num & (1 << k)) && k != j) {
            ans += prob[k][j];
        }
    }
    ans = ans / (1.0 * den);
    return ans;
}
ll tot = 0;

typedef pair<ll, ll> pi;
// vector <ll> dijkstra(ll V, vector<vector<pair<ll, ll>>> adj, ll s, vll &par)
// {
//     priority_queue<pi, vector<pi>, greater<pi> > pq;
//     pq.push({0, s});
//     vector<ll>dist(V, LLONG_MAX);
//     // vll par(V,-1);
//     dist[s] = 0;
//     while (!pq.empty()) {
//         ll dis = pq.top().first;
//         ll ind = pq.top().second;
//         pq.pop();
//         for (auto it : adj[ind]) {
//             if (dist[it.ff] > dis + it.ss) {
//                 par[it.ff] = ind ;
//                 dist[it.ff] = dis + it.ss;
//                 pq.push({dist[it.ff], it.ff});
//             }
//         }
//     }
//     return dist;
// }


// void build (ll ind, ll l, ll r, vll &v, vll &seg) {
//     if (l == r) { seg[ind] = (v[l]); return;}
//     ll mid = (l + r) / 2;
//     build(2 * ind + 1, l, mid, v, seg);
//     build(2 * ind + 2, mid + 1, r, v, seg);
//     ll lft = seg[2 * ind + 1], rgt = seg[2 * ind + 2];
//     seg[ind] = min(lft, rgt);
//     return ;
// }
// void update(ll ind, ll low, ll high, ll l, ll r, ll val, vll &seg) {
//     //update previous remaining updates

//     if (high < l || r < low) return;
//     if (low >= l && high <= r) {
//         seg[ind] += val;

//         return ;
//     }
//     ll mid = (low + high) / 2;
//     update(2 * ind + 1, low, mid, l, r, val, seg);
//     update(2 * ind + 2, mid + 1, high, l, r, val, seg);
//     seg[ind] = (seg[2 * ind + 1] + seg[2 * ind + 2]);

// }
// ll query(ll ind, ll low, ll high, ll l, ll r, vll &seg) {
//     // if (lazy[ind] != 0) {
//     //     seg[ind] += lazy[ind];
//     //     if (low != high) {
//     //         lazy[2 * ind + 1] += lazy[ind];
//     //         lazy[2 * ind + 2] += lazy[ind];
//     //     }
//     //     lazy[ind] = 0;
//     // }
//     if ((r < low) || (l > high)) {
//         return INT_MAX;
//     }
//     if (low >= l && high <= r) {
//         return seg[ind];
//     }
//     ll mid = (low + high) / 2;
//     // ll ans = (1LL << 31) - 1;

//     ll lft = query(2 * ind + 1, low, mid, l, r, seg);
//     ll rgt = query(2 * ind + 2, mid + 1, high, l, r, seg);
//     return min(lft, rgt);
// }
// ll query(ll x) {
//     cout << x << endl;
//     cout.flush();
//     ll y;
//     cin >> y;
//     if (y == 0 || y == -2) {
//         exit(0);
//     }
//     return y;
// }
// const ll N = 2 * 1e5 + 10;
// vll fac(N, 1), inv(N, 1);

// void dfs(ll i, vvll&adj, vll &vis) {
//     // dp[i] = w[i];
//     vis[i] = 1;

//     // ans = max(ans, dp[i]);
//     for (auto it : adj[i]) {
//         if (vis[it]) continue;
//         dfs(it, adj, vis);

//     }

// }
bool ok ;

// const ll N = 2e5 + 10;
// ll fac[N + 1], inv[N + 1];
// ll ncr(ll n, ll r) {
//     if (n < r) return 0;
//     ll ans = (((fac[n] * inv[n - r]) % mod) * inv[r]) % mod;
//     return ans;
// }
void build (ll ind, ll l, ll r, vll &v, vll &seg) {
    if (l == r) { seg[ind] = v[l]; return;}
    ll mid = (l + r) / 2;
    build(2 * ind + 1, l, mid, v, seg);
    build(2 * ind + 2, mid + 1, r, v, seg);
    seg[ind] = max(seg[2 * ind + 1], seg[2 * ind + 2]);
    return ;
}
// ll query(ll ind, ll low, ll high, ll l, ll r, vll &seg) {

//     if (r < low || l > high) {
//         return LLONG_MIN / 2;
//     }
//     if (low >= l && high <= r) {
//         return seg[ind];
//     }
//     ll mid = (low + high) / 2;
//     ll lft = query(2 * ind + 1, low, mid, l, r, seg);
//     ll rgt = query(2 * ind + 2, mid + 1, high, l, r, seg);
//     return max(lft, rgt);
// }

// void update(ll ind, ll low, ll high, ll l, ll r, ll val, vll &seg) {
//     //update previous remaining updates

//     if (high < l || r < low) return;
//     if (low >= l && high <= r) {
//         seg[ind] += val;

//         return ;
//     }
//     ll mid = (low + high) / 2;
//     update(2 * ind + 1, low, mid, l, r, val, seg);
//     update(2 * ind + 2, mid + 1, high, l, r, val, seg);
//     seg[ind] = (seg[2 * ind + 1] + seg[2 * ind + 2]);

// }
vll help(ll l, ll r, vll curr, vll &v) {

    for (ll i = r; i >= l; i--) curr.pb(v[i]);
    for (ll i = 0; i < l; i++) curr.pb(v[i]);
    return curr;
}
void dfs(ll i, vector<set<ll>>&adj, vll &vis, ll par) {
    // dp[i] = w[i];
    vis[i] = 1;
    ll mx = 0;
    // ans = max(ans, dp[i]);
    for (auto it : adj[i]) {
        if (vis[it] && it != par) {ok = false;}
        if (!vis[it]) dfs(it, adj, vis, i);

    }


}
bool helper(ll x) {
    ll y = llround(sqrt(x));
    return y * y == x;
}
int  help(vii &v, ll x) {
    int cnt = 0;
    for (auto it : v) {
        if (helper(it + x)) {
            cnt++;

        }
    }
    return cnt;
}
ll query(vll &v) {
    cout << "? ";
    for (auto it : v) cout << it << " ";
    cout << endl;
    cout.flush();
    ll x;
    cin >> x;
    return x;
}
bool check(ll x, vll &v) {
    ll n = v.size();
    ll i = 0, j = n - 1;
    while (i < n) {
        if (v[i] - v[0] > 2 * x) break;
        i++;
    }
    while (j >= 0) {
        if (v.back() - v[j] > 2 * x) break;
        j--;
    }
    if (i > j) return true;
    if (v[j] - v[i] > 2 * x) return false;
    return true;
}
bool isval(ll i, ll j, ll n, ll m) {
    if ((i < 0) || (j < 0) || (i >= n) || ( j >= m)) return false;
    return true;
}
void help(ll i, ll j, vvll &vis, ll req, vvcc &mat, vvcc &ans, char c) {
    ll cnt = 1;
    ll n = mat.size(), m = mat[0].size();
    vis[i][j] = 1;
    queue<pll>q;
    q.push({i, j});
    while (!q.empty()) {
        ll x = q.front().ff;
        ll y = q.front().ss;
        q.pop();
        // cout << c << " ";
        // ans[x][y] = c;
        // cout << ans[x][y] << " ";
        if (isval(x + 1, y, n, m)) {
            if (((mat[x + 1][y] != 'R' ) || (cnt < req)) && (!vis[x + 1][y])) {
                // if (mat[x + 1][y] == 'R' ) cnt++;
                vis[x + 1][y] = 1;
                q.push({x + 1, y});
            }

        }
        if (isval(x - 1, y, n, m)) {
            if (((mat[x - 1][y] != 'R') || (cnt < req)) && (!vis[x - 1][y])) {
                // if (mat[x - 1][y] == 'R' ) cnt++;
                vis[x - 1][y] = 1;
                q.push({x - 1, y});
            }

        }
        if (isval(x, y + 1, n, m)) {
            if (((mat[x][y + 1] != 'R') || (cnt < req)) && (!vis[x][y + 1])) {
                // if (mat[x][y + 1] == 'R' ) cnt++;
                vis[x][y + 1] = 1;
                q.push({x , y + 1});
            }

        }
        if (isval(x, y - 1, n, m)) {
            if (((mat[x][y - 1] != 'R' ) || (cnt < req)) && (!vis[x][y - 1])) {
                // if (mat[x][y - 1] == 'R' ) cnt++;
                vis[x][y - 1] = 1;
                q.push({x, y - 1});
            }

        }
    }
    return;
}
void yahapekrege() {
    ll n;
    cin >> n;
    if (n <=4) cout << "Bob";
    else cout << "Alice";
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    // fac[0] = 1, fac[1] = 1;
    // for (ll i = 2; i <= N; i++) {
    //     fac[i] = (fac[i - 1] * i) % mod;
    // }
    // inv[N] = inverse(N, mod);
    // for (ll i = N - 1; i >= 0; i--) {
    //     inv[i] = inverse(i, mod);
    // }
    // sieve(N);
    int t;
    cin >> t;
    //
    while (t--) {
        //     // cout<<"Case #"<<a<<": ";

        yahapekrege();
        //     // a++;
        cout << endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets