276B - Little Girl and Game - CodeForces Solution


games greedy *1300

Please click on ads to support us..

Python Code:

from collections import Counter
s = input()
c = Counter(s)
even = {}
odd = {}
for key, value in c.items():
    if value % 2 == 0:
        even[key] = value
    else:
        odd[key] = value
i = 0
while True:
    if len(odd) <= 1: 
        print('First' if i % 2 == 0 else 'Second')
        break
    if even:
        key, value = even.popitem()
        odd[key] = value - 1
    else:
        key, value = odd.popitem()
        if value > 1:
            even[key] = value - 1
    i += 1

            

C++ Code:

#include<cstring>
    #define push_back pb
    #define push_front pf
    #define first F
    #define second S
    #include <bits/stdc++.h>
    #include <string>
    #define all(a) a.begin(), a.end()
    #define allr(a) a.rbegin(), a.rend()
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    const ll N = 1e5;
    const ll INF =5e18;
    const ll mod = 1e9+7;
    map<ll,ll>mp;
//    map<ll,ll>mp,cnt;
//    ll gcd(ll a,ll b){
//        if(a==0 || b==0) return a+b;
//        return gcd(b,a%b);
//    }
//    ll num[N];
//    set<ll>s;
//    vector<ll>primes;
//    void seive(){
//        num[2]=2;
//        for(int i = 3;i<N;i+=2){
//            num[i]=i;
//        }
//        for(int i = 3;i*i<N;i++){
//            if(num[i]==i){
//                for(int j = i*i;j<N;j+=i){
//                    num[j]=0;
//                }
//            }
//        }
//        for(int i = 2;i<N;i++){
//            if(num[i]==i){
//                primes.pb(i);
//            }
//        }
//    }
//    bool is_prime(ll n){
//        for(int i = 2;i*i<=n;i++){
//            if(n%i==0){
//                return false;
//            }
//        }
//        return true;
//    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
//        ll t;
//        cin>>t;
//        while(t--){
            string s;
            cin>>s;
            ll cnt[26+1]={0};
            for(int i=0;i<s.size();i++){
                cnt[s[i]-'a'+1]++;
            }
            ll od=0;
            ll ev=0;
            ll ans=0;
            for(int i = 1;i<=26;i++){
                if(cnt[i]){
                    ans++;
                }
                if(cnt[i]&1){
                    od++;
                }
                else{
                    ev++;
                }
            }
            if(od==1 || od==0 || (od&1)){
                cout<<"First"<<endl;
            }

            else{
                cout<<"Second"<<endl;
            }

//        }






        return 0;
    }


Comments

Submit
0 Comments
More Questions

519A - A and B and Chess
725B - Food on the Plane
154B - Colliders
127B - Canvas Frames
107B - Basketball Team
245A - System Administrator
698A - Vacations
1216B - Shooting
368B - Sereja and Suffixes
1665C - Tree Infection
1665D - GCD Guess
29A - Spit Problem
1097B - Petr and a Combination Lock
92A - Chips
1665B - Array Cloning Technique
1665A - GCD vs LCM
118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate