# Google Kick Start Archive — Round A 2015 problems

## A. Googol String

### Problem

A "0/1 string" is a string in which every character is either `0` or `1`. There are two operations that can be performed on a 0/1 string:

• switch: Every `0` becomes `1` and every `1` becomes `0`. For example, "100" becomes "011".
• reverse: The string is reversed. For example, "100" becomes "001".

Consider this infinite sequence of 0/1 strings:

S0 = ""

S1 = "0"

S2 = "001"

S3 = "0010011"

S4 = "001001100011011"

...

SN = SN-1 + "0" + switch(reverse(SN-1)).

You need to figure out the Kth character of Sgoogol, where googol = 10100.

### Input

The first line of the input gives the number of test cases, T. Each of the next T lines contains a number K.

### Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the Kth character of Sgoogol.

### Limits

Time limit: 30 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.

1 ≤ K ≤ 105.

1 ≤ K ≤ 1018.

### Sample

Sample Input
```4
1
2
3
10
```
Sample Output
```Case #1: 0
Case #2: 0
Case #3: 1
Case #4: 0

```

## B. gCube

### Problem

Googlers are very interested in cubes, but they are bored with normal three-dimensional cubes and also want to think about other kinds of cubes! A "D-dimensional cube" has D dimensions, all of equal length. (D may be any positive integer; for example, a 1-dimensional cube is a line segment, and a 2-dimensional cube is a square, and a 4-dimensional cube is a hypercube.) A "D-dimensional cuboid" has D dimensions, but they might not all have the same lengths.

Suppose we have an N-dimensional cuboid. The N dimensions are numbered in order (0, 1, 2, ..., N - 1), and each dimension has a certain length. We want to solve many subproblems of this type:

1. Take all consecutive dimensions between the Li-th dimension and Ri-th dimension, inclusive.

2. Use those dimensions to form a D-dimensional cuboid, where D = Ri - Li + 1. (For example, if Li = 3 and Ri = 6, we would form a 4-dimensional cuboid using the 3rd, 4th, 5th, and 6th dimensions of our N-dimensional cuboid.)

3. Reshape it into a D-dimensional cube that has exactly the same volume as that D-dimensional cuboid, and find the edge length of that cube.

Each test case will have M subproblems like this, all of which use the same original N-dimensional cuboid.

### Input

The first line of the input gives the number of test cases, T. T test cases follow.

Each test case begins with two integers N and M; N is the number of dimensions and M is the number of queries. Then there is one line with N positive integers ai, which are the lengths of the dimensions, in order. Then, M lines follow. In the ith line, there are two integers Li and Ri, which give the range of dimensions to use for the ith subproblem.

### Output

For each test case, output one line containing "Case #x:", where x is the test case number (starting from 1). After that, output M lines, where the ith line has the edge length for the ith subproblem. An edge length will be considered correct if it is within an absolute error of 10-6 of the correct answer. See the FAQ for an explanation of what that means, and what formats of real numbers we accept.

### Limits

Time limit: 30 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.
1 ≤ ai ≤ 109.
0 ≤ LiRi < N.

1 ≤ N ≤ 10.
1 ≤ M ≤ 10.

1 ≤ N ≤ 1000.
1 ≤ M ≤ 100.

### Sample

Sample Input
```2
2 2
1 4
0 0
0 1
3 2
1 2 3
0 1
1 2

```
Sample Output
```Case #1:
1.000000000
2.000000000
Case #2:
1.414213562
2.449489743
```

## C. gCampus

### Problem

Company G has a main campus with N offices (numbered from 0 to N - 1) and M bidirectional roads (numbered from 0 to M - 1). The ith road connects a pair of offices (Ui, Vi), and it takes Ci minutes to travel on it (in either direction).

A path between two offices X and Y is a series of one or more roads that starts at X and ends at Y. The time taken to travel a path is the sum of the times needed to travel each of the roads that make up the path. (It's guaranteed that there is at least one path connecting any two offices.)

Company G specializes in efficient transport solutions, but the CEO has just realized that, embarrassingly enough, its own road network may be suboptimal! She wants to know which roads in the campus are inefficient. A road is inefficient if and only if it is not included in any shortest paths between any offices.

Given the graph of offices and roads, can you help the CEO find all of the inefficient roads?

### Input

The first line of the input gives the number of test cases, T. T test cases follow. Each case begins with one line with two integers N and M, indicating the number of offices and roads. This is followed by M lines containing three integers each: Ui, Vi and Ci, indicating the ith road is between office Ui and office Vi, and it takes Ci minutes to travel on it.

### Output

For each test case, output one line containing "Case #x:", where x is the test case number (starting from 1). Then output the road numbers of all of the inefficient roads, in increasing order, each on its own line. (Note that road 0 refers to the first road listed in a test case, road 1 refers to the second road, etc.)

### Limits

Time limit: 30 seconds per test set.
Memory limit: 1GB.
0 < Ci ≤ 1000000.

1 ≤ T ≤ 10.
1 ≤ N = M ≤ 100.

1 ≤ T ≤ 3.
1 ≤ N ≤ 100.
1 ≤ M ≤ 10000.

### Sample

Sample Input
```2
3 3
0 1 10
1 2 3
2 0 3
3 3
0 1 10
1 2 3
2 1 3```
Sample Output
```Case #1:
0
Case #2:```

## D. gSnake

### Problem

Alex is a huge fan of the Snake game.

Note: This Google Doodle does not exactly match the rules of the Snake game we will describe below. It is only intended to give you a general idea of what the game looks like.

Alex just learned how to program and wants to develop his own version of Snake, with the following rules:

• The game board has R rows and C columns. The top left cell of the board has coordinates (1, 1), and the bottom right cell has coordinates (R, C).
• At the start of the game, in every cell with coordinates (r, c) such that r + c is odd, there is one piece of food. No other cells have food.
• The snake's body is always an ordered, connected sequence of one or more cells on the board. The first cell of the sequence is called the "head" of the snake. The second cell (if any) shares an edge (not just a corner) with the first cell, and so on. The last cell in the sequence is called the "tail" of the snake.
• The snake's head is always facing in one of four directions: left, up, right, or down.
• At the start of the game, the snake is at cell (1, 1) and has a length of one (that is, the snake consists of only a head), and the head faces right.
• At each integer time (1 second, 2 seconds, etc.), the head of the snake will move into the adjacent cell that its head is facing toward. The board is cyclic, i.e., trying to move off an edge will cause the head to appear on the opposite edge of the board. For example, if the snake is at (1, C) and its head is facing right, the head will next move to (1, 1). If the snake is at (1, C) and its head is facing up, the head will next move to (R, C).
• When the snake's head moves into a cell with no food, the snake does not grow. The snake's second cell (if any) moves to the place where the snake's head was, the snake's third cell (if any) moves to the place where the second cell was, and so on.
• When the snake's head moves into a cell with a piece of food, it eats the food (meaning that cell no longer has food), and grows its body. A new head is created in the cell where the food was. The cell that was the snake's head becomes the snake's second cell, the cell that was the snake's second cell (if any) becomes the snake's third cell, and so on.
• If, after a move is complete, the snake's head is in the same place as one of another of its cells, the snake dies and the game ends immediately. (Note that if the snake's head moves toward a cell where its tail was, the game will not end, because the tail will move out of the way before the move is complete.)
• In the game, the player can let the snake perform some turn actions. Each action Ai will happen between the Tith and Ti+1 th seconds. There are two possible actions: "L" and "R". An "L" action will turn the head 90 degrees to the left, so, for example, if the snake had been facing down before, it would face right after. An "R" action will turn the head 90 degrees to the right, so, for example, if the snake had been facing down before, it would face left after.
• The game has a time limit: it will end after the move on the 109th second is complete (if the game has even gone on that long!)

To test the game, Alex has written a series of TURN actions. Your task is to simulate that series of actions, and tell Alex the final length of the snake when the game is over. Remember that the game can end either because the snake's head and another cell of its body are in the same place after a move is complete, or because time runs out. In the former case, you should count both the head and the overlapping cell of its body as two separate cells, for the purpose of determining length.

### Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test cases starts with three integers S, R, and C, where S gives the number of turn actions and R and C represent the number of rows and columns of the board. S lines follow; the ith of these lines has an integer Xi, then a character Ai that is either `L` or `R`. Each of these lines corresponds to performing an action between Xith and Xi+1 th seconds. It's guaranteed that the actions are given in time order and there will never be more than one action between the same two seconds. However, you should note that the game may end before the snake gets to execute all of these actions.

### Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the length of the snake when the game is over.

### Limits

Memory limit: 1GB.
1 ≤ T ≤ 10.

#### Small dataset (Test Set 1 - Visible)

Time limit: 30 seconds.
1 ≤ R, C ≤ 100;
1 ≤ S ≤ 100;
1 ≤ Xi ≤ 2000.

#### Large dataset (Test Set 2 - Visible)

Time limit: 60 seconds.
1 ≤ R, C ≤ 100000;
1 ≤ S ≤ 100000;
1 ≤ Xi ≤ 1000000.

### Sample

Sample Input
```2
3 3 3
1 R
2 L
3 R
5 3 3
2 R
4 R
6 R
7 R
8 R
```
Sample Output
```Case #1: 3
Case #2: 5
```

## Analysis — A. Googol String

Test Data
info We recommend that you practice debugging solutions without looking at the test data.

## Analysis — B. gCube

Test Data
info We recommend that you practice debugging solutions without looking at the test data.

## Analysis — C. gCampus

Test Data
info We recommend that you practice debugging solutions without looking at the test data.

## Analysis — D. gSnake

Test Data
info We recommend that you practice debugging solutions without looking at the test data.

## Statistics — A. Googol String

### Test set 1: 2083 correct solutions (91.4% solve rate)

First
shakilaust 7:16
uSeemSurprised 8:09
akovski 8:45
cebrusfs 8:55

First
akovski 8:45
cebrusfs 8:55
once 12:11
miteshag 12:25
nfssdq 12:38

## Statistics — B. gCube

### Test set 1: 1557 correct solutions (68.3% solve rate)

First
VishalTheBeast 14:03
satyaki3794 14:14
usaxena95 14:30
Cute ivory narwhal 14:41
avastpulkit 16:36

### Test set 2: 855 correct solutions (37.5% solve rate)

First
VishalTheBeast 14:03
usaxena95 14:30
avastpulkit 16:36
zjsxzy 19:01
devanshdalal2 19:06

## Statistics — C. gCampus

### Test set 1: 493 correct solutions (21.6% solve rate)

First
reus 17:26
Courageous khaki pumpkin 20:34
Lquartz 25:49
satyaki3794 26:48
amankedia1994 29:45

### Test set 2: 227 correct solutions (10.0% solve rate)

First
reus 17:26
Courageous khaki pumpkin 20:34
satyaki3794 26:48
amankedia1994 29:45
tiansh 30:59

## Statistics — D. gSnake

### Test set 1: 121 correct solutions (5.3% solve rate)

First
cebrusfs 84:46
orenguy 85:24
sgtlaugh 89:52
Oo.Light.oO 92:07
nfssdq 92:46

First
cebrusfs 84:46
sgtlaugh 89:52
nfssdq 92:46
usaxena95 96:47
akovski 98:18