Cerinta completa

It’s New Year’s Day, and Balsa and Koca are stuck inside watching the rain. They decide to invent a game, the rules for which are described below.

Given array containing integers, they take turns making a single move. Balsa always moves first, and both players are moving optimally (playing to win and making no mistakes).

During each move, the current player chooses one element from , adds it to their own score, and deletes the element from ; because the size of decreases by after each move, ‘s size will be after moves and the game ends (as all elements were deleted from ). We refer to Balsa’s score as and Koca’s score as . Koca wins the game if || is divisible by ; otherwise Balsa wins.

Given , determine the winner.

Note: .

Input Format

The first line contains an integer, , denoting the number of test cases.
Each test case is comprised of two lines; the first line has an integer , and the second line has space-separated integers describing array .

Constraints



Subtasks

For score:
For score:

Output Format

For each test case, print the winner’s name on a single line; if Balsa wins print Balsa, otherwise print Koca.

Sample Input

2 
3
7 6 18
1
3

Sample Output

Balsa
Koca

Explanation

Test Case 1

Array . The possible play scenarios are:

  1. , , , and .

  2. , , , and .

  3. , , , and .

In this case, it doesn’t matter what Balsa chooses because the difference between their scores isn’t divisible by . Thus, Balsa wins.

Test Case 2

Array . Balsa must choose that element, the first move ends the game.

, , , and . Thus, Koca wins.


Limbajul de programare folosit: java8

Cod:

import java.io.*;

public class Solution {
    private static class FastScanner {
        private final InputStream in;
        private final byte[] buffer = new byte[1 << 16];
        private int ptr = 0, len = 0;
        FastScanner(InputStream is) { this.in = is; }
        private int read() throws IOException {
            if (ptr >= len) {
                len = in.read(buffer);
                ptr = 0;
                if (len <= 0) return -1;
            }
            return buffer[ptr++];
        }
        int nextInt() throws IOException {
            int c;
            do { c = read(); } while (c <= ' ' && c != -1);
            int sign = 1;
            if (c == '-') { sign = -1; c = read(); }
            int val = 0;
            while (c > ' ') {
                val = val * 10 + (c - '0');
                c = read();
            }
            return val * sign;
        }
    }

    public static void main(String[] args) throws Exception {
        FastScanner fs = new FastScanner(System.in);
        int T = fs.nextInt();
        StringBuilder out = new StringBuilder();

        while (T-- > 0) {
            int n = fs.nextInt();
            int c1 = 0, c2 = 0;
            for (int i = 0; i < n; i++) {
                int x = fs.nextInt() % 3;
                if (x == 1) c1++;
                else if (x == 2) c2++;
            }

            if ((c1 % 2 == 0) && (c2 % 2 == 0)) out.append("Koca\n");
            else out.append("Balsa\n");
        }

        System.out.print(out);
    }
}

Scor obtinut: 1.0

Submission ID: 464620136

Link challenge: https://www.hackerrank.com/challenges/newyear-game/problem

New Year Game