AtCoder Beginner Contest 166
Problem A: A?C
Check the element at 1st index and print “ARC” or “ABC” accordingly.
Code
Problem B: Trick or Treat
Simplified problem:
- Given N bins and K type of balls, each type of ball is present in some bins.
- Find the count of bins in which no there is no ball.
Hint
- Just build a count array denoting the no. of balls present in a particular bin.
- The answer is just the count of bins having ZERO balls present in them.
Code
Problem C: Peaks
Simplified problem:
- Given a graph with N nodes and M undirected edges, and each node has a value H[i] associated with it.
- Find the count of nodes which either do not have any adjacent nodes, or whose value is more than all of its adjacent nodes.
Hint
- Create an adjacency list and the answer is the sum of nodes with no element in this list or
- the nodes whose all elements in the adjacency list have a value less than the node's value.
Code
Problem D: I hate factorization
Simplified problem: Given an integer X find integers A and B such that
Hint
- Since X is an integer, can we somehow brute force over values of A and B?
- Can A and B ever exceed 1000? (The limit can be further narrowed)
Code
Problem E: This Message Will Self-Destruct in 5s
Simplified problem: Given an array arr containing N integers, find the no. of pairs
where and
Hint
- Try to rearrange the expression to bring terms containing i and j separately. $$ j - arr[j] = i + arr[i] $$
- So, you need to count the pair of indices in the array for which the above expression holds true.
- As you iterate over the array, store the count of say (i + arr[i]) in a map (say cnt), also add $$ cnt[i - arr[i]] $$ to the result before adding to count of (i + arr[i]). This will count the pairs where the current index is the second one in the pair. It will be more clear in the code below.
Code
Problem F: Three Variables Game
Simplified problem: