2015年3月16日 星期一

Codechef January Challenge 2015 Chef and A Large Permutation

// http://www.codechef.com/problems/CLPERM
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

int T;
int N, K;

vector<int> v;

int main()
{
    scanf("%d", &T);

    while( T-- )
    {
        scanf("%d %d", &N, &K);

        v.clear();

        for(int Ki = 0; Ki < K; Ki++)
        {
            int x;
            scanf("%d", &x);
            v.push_back(x);
        }

        sort(v.begin(), v.end());

        bool dec = false;
        int past = 0;
        ll sum = 0;

        for(int vi = 0; vi < v.size(); vi++)
        {
            int x = v[vi]-1;

            sum += ll(past+x+1)*(x-past)/2;

            if( sum < v[vi] && !dec )
            {
                dec = true;

                if( sum % 2 == 0 ) puts("Chef");
                else puts("Mom");
            }

            past = v[vi];
        }

        sum += ll(past+N+1)*(N-past)/2;

        if( !dec )
        {
            dec = true;

            if( sum % 2 == 0 ) puts("Chef");
            else puts("Mom");
        }
    }
}

沒有留言:

張貼留言