Mixi Game CodeChef Solution

Problem -Mixi Game CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

Mixi Game CodeChef Solution in C++14


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define Time cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#define pb push_back
#define mp make_pair
#define line cout << endl;
#define ff first
#define ss second
#define vi vector<int>
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;
#define printv(v)                      \
  for (int i = 0; i < (v.size()); i++) \
  {                                    \
    cout << v[i] << " ";               \
  }                                    \
  line;
#define onesbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define sp(x, y) fixed << setprecision(y) << x
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)
#define tk(x) \
  int x;      \
  cin >> x;
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
#define debug(x)     \
  cerr << #x << " "; \
  _print(x);         \
  cerr << endl;
#else
#define debug(x)
#endif
template <class T>
void _print(T t)
{
  cerr << t;
}

template <class T, class V>
void _print(pair<T, V> p)
{
  cerr << "{";
  _print(p.ff);
  cerr << ",";
  _print(p.ss);
  cerr << "}";
}

template <class T>
void _print(vector<T> v)
{
  cerr << "[ ";
  for (T i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

template <class T>
void _print(vector<vector<T>> v)
{
  cerr << "[\n";
  for (int l = 0; l < v.size(); l++)
  {
    {
      for (int k = 0; k < v[l].size(); k++)
        cerr << v[l][k] << " ";
    }
    cerr << "\n";
  }
  cerr << "]";
}

template <class T, class V>
void _print(map<T, V> v)
{
  cerr << "[ ";
  for (auto i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

template <class T>
void _print(set<T> v)
{
  cerr << "[ ";
  for (T i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

const long long inf = 1e18;
const int MOD = 1e9 + 7;
const int MAX = 1e6;

int numbit(int x)
{
    int ans = 0;
    while (x > 0)
    {
        x = x >> 1;
        ans++;
    }
    return ans;
}

int setbit(int x)
{
    int ans = 0;
    while (x > 0)
    {
        if (x & 1)
        {
            ans++;
        }
        x = x >> 1;
    }
    return ans;
}

bool isValid(string s)
{
  int len = s.size();
  for (int i = 0; i < len / 2; i++)
  {
    if (s[i] != s[len - 1 - i])
      return false;
  }
  return true;
}

void rotateMatrix(vector<vector<int>> &v, int n)
{
  for (int i = 0; i < n / 2; i++)
  {
    for (int j = i; j < n - i - 1; j++)
    {
      int ptr = v[i][j];
      v[i][j] = v[n - 1 - j][i];
      v[n - 1 - j][i] = v[n - 1 - i][n - 1 - j];
      v[n - 1 - i][n - 1 - j] = v[j][n - 1 - i];
      v[j][n - 1 - i] = ptr;
    }
  }
}

vector<bool> is_prime(10001, 1);
vector<int> primes;

void seive()
{
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i < 10001; i++)
  {
    if (is_prime[i])
    {
      primes.push_back(i);
      for (int j = i + i; j < 10001; j += i)
      {
        is_prime[j] = 0;
      }
    }
  }
}

ll expo (ll x,ll n){
    ll result=1;
    while (n) {
        if (n & 1)
            result = result * x % MOD;
        n = n / 2;
        x = x * x % MOD;
    }
    return result;
}



int32_t main() {
  ll t; cin >> t;
  // seive();
  while (t--) {
    ll n,m,sum=0; cin>>n>>m;

    ll a;

    for (ll i = 0; i <n; i++)
    {
      /* code */
      cin>>a;
      if((i%2==0))
        sum=max(abs(sum+a),abs(sum-a));
      else 
        sum=min(abs(sum+a),abs(sum-a));
    }

    if(sum>=m) cout<<1<<endl;
    else cout<<2<<endl;
      

  }
  return 0;
}

// 1b 4d

Mixi Game CodeChef Solution in PYTH 3

# cook your dish here
def integer_list():
	return list(map(int, input().split()))

def string_list():
	return list(map(str, input().split()))

def hetro_list():
	return list(input().split())





import math	

from collections import Counter


def solve():

	#∣V∣≥K  the winner is Vanja; 


	v1 = 0
	for i, v in enumerate(lst):
		if i%2 == 0:
			if v1 < 0:
				v1 -= v
			else:
				v1 += v
		else:
			if v1 > 0:
				v1 -= v
			else:
				v1 += v
	if abs(v1) >= k:
		print(1)
	else:
		print(2)



t = int(input())

for _ in range(t):
	n, k = integer_list()
	lst = integer_list()
	solve()

Mixi Game CodeChef Solution in C

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--){
		int n,k,i,j,l=0;
		scanf("%d %d",&n,&k);
		for(i=0;i<n;i++){
			scanf("%d",&j);
			if(j==1){
				if(i%2==0)
				l > 0 ? l++ : l--;
				else
				l > 0 ? l-- : l++;
			}
		}
		abs(l) < k ? printf("2\n") : printf("1\n");
	}
	return 0;
}

Mixi Game CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		for (int i=1;i<=t;i++)
		{
		    int n=in.nextInt();
		    int k=in.nextInt();
		    int[] arr=new int[n];
		    int v=0;
		    for (int j=0;j<n;j++)
		    {
		        arr[j]=in.nextInt();
		        if(arr[j]==1)
		        {
		            if((j&1)==0)
		            {
		                if(v>=0)
		                {
		                    v+=1;
		                }
		                else
		                v-=1;
		            }
		            else
		            {
		                if(v>=0)
		                {
		                    v-=1;
		                }
		                else
		                v+=1;
		            }
		        }
		    }
		    int x=(int)Math.abs(v);
		    if(x>=k)
		    {
		        System.out.println(1);
		    }
		    else
		    System.out.println(2);
		}
	}
}

Mixi Game CodeChef Solution in PYPY 3

t = int(input())

for i in range(t):
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    sum = 0
    for j in range(n):
        if j%2 == 0:
            if sum == 0:
                sum+=l[j]
            elif sum>0:
                sum+=l[j]
            else:
                sum-=l[j]
        else:
            if sum>0:
                sum-=l[j]
            elif sum<=0:
                sum+=l[j]
    if abs(sum)>=k:
        print(1)
    else:
        print(2)

Mixi Game CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	st = raw_input().split()
	N = int(st[0])
	K = int(st[1])
	tot = 0
	st = raw_input().split()
	p = 0
	for x in st:
		n = int(x)
		if p == 0:
			tot += n
		else:
			tot = abs(tot-n)
		# endif
		p = 1-p
	# endfor x
	if tot < K:
		print '2'
	else:
		print '1'
	# endif
# endfor i

Mixi Game CodeChef Solution in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CookOffaug182
{
    class Program
    {
        static void Main(string[] args)
        {
            int testCases;
            testCases = int.Parse(Console.ReadLine());
            string read;

            List<int> ArrayA = new List<int>();
            while (testCases-- > 0)
            {
                read = Console.ReadLine();
                int n = int.Parse(read.Split(' ').ToList()[0]);
                int k = int.Parse(read.Split(' ').ToList()[1]);


                read = Console.ReadLine();
                ArrayA = (read.Split(' ').ToList()).Select(s => int.Parse(s)).ToList();

                int score = 0;
                int counter = 0;
                foreach (var a in ArrayA)
                {
                    counter++;

                    if ((counter % 2 == 1) && (a == 1))
                    {
                        if (score < 0)
                        {
                            score = score - 1;
                        }
                        else
                        {
                            score = score + 1;
                        }
                    }
                    if ((counter % 2 == 0) && (a == 1))
                    {
                        if (score < 0)
                        {
                            score = score + 1;
                        }
                        else
                        {
                            score = score - 1;
                        }
                    }
                }

                if (Math.Abs(score) >= k)
                    Console.WriteLine(1);
                else
                    Console.WriteLine(2);
            }
        }
    }
}

Mixi Game CodeChef Solution in GO

package main

import (
	"bufio"
	"fmt"
	"os"
)

const MAX_N = 30010

var input []int

func init() {
	input = make([]int, MAX_N)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	tmp := 0
	for i < len(bytes) && bytes[i] != ' ' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp
	return i
}

func readNum(scanner *bufio.Scanner) (a int) {
	scanner.Scan()
	readInt(scanner.Bytes(), 0, &a)
	return
}

func readTwoNums(scanner *bufio.Scanner) (a int, b int) {
	scanner.Scan()
	x := readInt(scanner.Bytes(), 0, &a)
	readInt(scanner.Bytes(), x+1, &b)
	return
}

func readNNums(scanner *bufio.Scanner, n int) []int {
	// res := make([]int, n)
	x := -1
	scanner.Scan()
	for i := 0; i < n; i++ {
		x = readInt(scanner.Bytes(), x+1, &input[i])
	}
	return input[:n]
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	tc := readNum(scanner)

	for tc > 0 {
		tc--
		N, K := readTwoNums(scanner)
		A := readNNums(scanner, N)
		fmt.Println(solve(N, A, K))
	}
}

func solve(n int, A []int, K int) int {
	var X int

	for i := 0; i < n; i++ {
		if A[i] == 0 {
			continue
		}
		if i&1 == 0 {
			X++
		} else {
			if X == 0 {
				X++
			} else {
				X--
			}
		}
	}
	if X >= K {
		return 1
	}
	return 2
}
Mixi Game CodeChef Solution Review:

In our experience, we suggest you solve this Mixi Game CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Mixi Game CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Mixi Game CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *