Главная

Популярная публикация

Научная публикация

Случайная публикация

Обратная связь

ТОР 5 статей:

Методические подходы к анализу финансового состояния предприятия

Проблема периодизации русской литературы ХХ века. Краткая характеристика второй половины ХХ века

Ценовые и неценовые факторы

Характеристика шлифовальных кругов и ее маркировка

Служебные части речи. Предлог. Союз. Частицы

КАТЕГОРИИ:






Problem B. Pluses and asterisks – 2




Problem A. Permugame

Input: standard input
Output: standard output
Memory limit: 256 Mb
Time limit: 0.5 sec

Ksyusha got a great present for her birthday - a “Permugame”. Gear for “Permugame” consists of the two permutations of size N: Pi, Qi and a square board N×N cells. According to the rules cells (i, j) and (a, b) are connected to each other by a tunnel if and only if either (a = i and b = Pj) or (a = Pi and b = j). The only goal of the game is to find such a minimal integer k (k > 0), that every cell of the board can be painted in one of the k colors. The only restriction is that any two connected cells should have different colors. Ksyusha is too lazy to play “Permugame” so she asked you to figure out the answer.

Input

In the first line you are given a single integer N (1 ≤ N ≤ 100000) ­­- size of the board and permutations P and Q. In the next line permutation Pi (1 ≤ Pi ≤ N) is given as a list of integers separated by spaces. In the third line permutation Qi (1 ≤ Q_i ≤ N) is given in the same format. It is guaranteed that Pi ≠ i and Qi ≠ i for each i in [1, N].

 

Output

Print the minimal integer k (k > 0) such that every cell of the N×N board can be painted in one of the k colors.

Sample input Sample output
2 1 2 1  
2 4 1 3 3 4 2 1  
5 3 4 2 1 2 5 4 3 1  

Problem B. Pluses and asterisks – 2

Input: standard input
Output: standard output
Memory limit: 256 Mb
Time Limit: 1 sec

Given a sequence of integers a1? a2? a3? …? aN one may replace each? with either + or *. After that, the expression is evaluated according to arithmetic rules, where + denotes addition, * denotes multiplication. Multiplication’s precedence is higher than addition’s, i.e. 2+2*2 is 6, not 8. In how many ways it is possible to make result equal to R?

Input

The 1st line contains space-separated integers N and R, denoting quantity of values ai and required result respectively. The 2nd line contains space-separated values a1, a2, a3, …, aN. 3≤N≤36, 1≤R≤242, 1≤ak≤217.

Output

Your program should write exactly one integer — the quantity of ways to obtain exactly R.

Sample input Sample output
4 8 2 2 2 2  

 

Note: The five ways are: 2+2+2+2; 2+2+2*2; 2+2*2+2; 2*2+2+2; 2*2+2*2.






Не нашли, что искали? Воспользуйтесь поиском:

vikidalka.ru - 2015-2024 год. Все права принадлежат их авторам! Нарушение авторских прав | Нарушение персональных данных