1738C - Even Number Addicts - CodeForces Solution


dp games greedy math

Please click on ads to support us..

Python Code:

def IsAliceWin(EvenCount,OddCount):
    if (OddCount%4) in [0,3]:
        return True
    return ((EvenCount%4) in [1,3]) and (OddCount%4==1)
for _ in range(int(input())):
    EvenCount,OddCount=[0,0]
    input()
    for i in list(map(int,input().split())):
        if i%2==0:
            EvenCount+=1
        else:
            OddCount+=1
    if IsAliceWin(EvenCount,OddCount):
        print("Alice")
    else:
        print("Bob")

C++ Code:

/*
ID: meadri01
LANG: C
TASK: test
*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int 				long long
#define w(t)                int t;cin>>t;while(t--)
#define pb                  push_back
#define mk                  make_pair
#define ascSort(v)          sort(v.begin(), v.end())
#define descSort(v)         sort(v.begin(), v.end(), greater<int>())
#define ff                  first
#define ss                  second
#define pi                  pair<int,int>
#define vi                  vector<int>
#define mi                  map<int,int>
#define fill(a,x)           fill(a.begin(), a.end(), x)
#define iota(a,x)           iota(a.begin(), a.end(), x)
#define umapi               unordered_map<int,int>

#define sz(x)               (int)x.size()
#define all(x)              x.begin(), x.end() 
#define ln                  "\n"

const int mod1=998244353;
const int mod2=1e12+7;
const int inf=mod2;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output1.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

void testcase(){
	int n;cin>>n;
	int odd=0;
	for(int i=0,a; i<n; i++){
		cin>>a;
		odd+=(abs(a)%2==1);
	}
	if(odd%4==0||odd%4==3||(odd%4==1&&(n-odd)%2==1))cout<<"Alice\n";
	else cout<<"Bob\n";
}

int32_t main(){
	
	FIO();
	//usaco("test");
	int t=1;
	cin>>t;
	for(int i=1; i<=t; i++){
		//cout<<"Case #"<<i<<": ";
		testcase();
	}
	return 0;
		
}


Comments

Submit
0 Comments
More Questions

1702C - Train and Queries
816B - Karen and Coffee
838D - Airplane Arrangements
148B - Escape
847G - University Classes
1110A - Parity
1215B - The Number of Products
604C - Alternative Thinking
1204C - Anna Svyatoslav and Maps
322A - Ciel and Dancing
1689B - Mystic Permutation
1711B - Party
1702D - Not a Cheap String
1714F - Build a Tree and That Is It
1703F - Yet Another Problem About Pairs Satisfying an Inequality
610A - Pasha and Stick
1200A - Hotelier
1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots
1690A - Print a Pedestal (Codeforces logo)
1295A - Display The Number
1077A - Frog Jumping
1714G - Path Prefixes
1369C - RationalLee
289B - Polo the Penguin and Matrix
1716A - 2-3 Moves