시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 50 | 20 | 18 | 43.902% |
Random Index Vectors (RIVs) are a relatively new technique for pattern matching. A RIV is a large, sparse vector of 1s and -1s. If randomly generated, the dot product of two RIVs is zero or very nearly zero, so they are orthogonal or very nearly orthogonal. They are used by assigning a RIV to various attributes, and then combining them in specific ways to form new vectors for patterns with those attributes. Then, the cosine of the angle between vectors for two patterns can be used as a measure of similarity between the patterns.
There are three basic operations on RIVs:
Because they are large and sparse, RIVs usually use a condensed representation. The vector is represented by a sorted list of indices (starting at 1) where there are non-zero values, with the index being negative if the value is -1. The representation starts with the number of non-zero indices.
For example, consider this RIV:
1 0 -1 0 0 0 -1 0 0 1 0
There are 4 non-zero elements at indices 1, 3, 7 and 10. In condensed representation:
4 1 -3 -7 10
Given two RIVs in condensed representation, add them, multiply them, and rotate them both. Give the resulting vectors in condensed form.
Each input will consist of a single test case. Note that your program may be run multiple times on different inputs.
Each test case will begin with a line with two space-separated integers n (1 ≤ n ≤ 1018) and k (1 ≤ k ≤ n), where n is the maximum index of the vectors and k is the number of spots to rotate by.
Each of the next two lines will have a vector in condensed form, starting with an integer m (0 ≤ m ≤ 1,000) followed by m indices i (1 ≤ |i| ≤ n), all separated by spaces.
Output four Random Index Vectors, one per line, in condensed form.
30 13 6 6 -9 -13 18 22 26 8 -1 3 7 11 13 19 20 -27
12 -1 3 6 7 -9 11 18 19 20 22 26 -27 1 -13 6 5 9 13 23 -26 -30 8 6 7 -14 -18 20 24 28 30
20 4 9 -2 -4 -8 -11 -12 15 18 19 20 7 4 5 -10 11 15 18 -20
8 -2 5 -8 -10 -12 15 18 19 5 -4 -11 15 18 -20 9 -4 -7 -8 11 14 15 16 -18 -20 7 1 -6 7 11 14 -16 20