COCI '18 Contest 1 #2 Zamjena

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 0.6s
Memory limit: 64M

Problem type

Vlatko likes to play with integer arrays. He wrote two arrays of N elements on a piece of paper, each element being either a positive integer or a sequence of lowercase letters of the English alphabet representing a variable. A variable can be replaced with an arbitrary integer. It's possible that both arrays contain the same variable or the same variable occurs multiple times in an array. If that's the case, each occurrence of the variable has to be replaced with the same integer in both arrays.

Vlatko wonders if it's possible to replace all variables with some integer values in such a way that the two arrays become equal. Two arrays are considered equal if the numbers on the same positions in the arrays are equal.

Input Specification

The first line contains a positive integer N (1 \le N \le 50\,000), the number of elements in each array.

The second line contains N elements of the first array.

The third line contains N elements of the second array.

Each element in both arrays can either be:

  • a positive integer less than 1\,000 or
  • a sequence of lowercase letters of the English alphabet (no longer than 10 characters) which represents a variable.

Output Specification

If it's possible to replace all variables with integer values in a way that the two arrays become equal, print DA (Croatian for yes). Otherwise print NE (Croatian for no).

Scoring

In test cases worth 20\% of the total points, each variable will occur exactly once in both arrays combined.

In test cases worth additional 20\% of the total points, there will be only two variables, x and y. It's possible that the variables appear multiple times in both arrays.

Sample Input 1

3
3 1 2
3 1 x

Sample Output 1

DA

Sample Input 2

4
4 5 iks ipsilon
1 iks 3 iks

Sample Output 2

NE

Sample Input 3

5
x 3 x y 3
x y 2 z 3

Sample Output 3

DA

Explanation for Sample Output 3

By introducing substitutions x = 2, y = 3, z = 3, both arrays will become equal (2\ 3\ 2\ 3\ 3).


Comments


  • 0
    dragonfire5906  commented on April 19, 2024, 4:59 a.m.

    Whoever added that leading zero in the input does not like to see people happy