Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INPUT:
- C - which subtask to solve
- S - string, max length 50000 characters, denotes the blue alphabet letters on the circle
- T - string, max length 25 characters, denotes the red letters of the alphabet on the circle
- Subtask 1:
- -uses only string S;
- -calculates the minimum time required to print S if the printer starts from 'A' and can go in both directions [(counter)clockwise];
- Subtask 2:
- -uses both strings S and T;
- -between every adjacent pair of blue letters in S, you are supposed to insert a red letter from T (so between S[0] and S[1] you would insert any letter from T);
- -you need to find and PRINT the minimum time required to print the new string (there can be multiple strings that achieve this minimum time -> say you have S = BBTH and T = AEIOU, then the strings that meet the minimum time are BABATIH, BABATOH, BABUTIH, BABUTOH);
- -you need to PRINT the number of strings that meet the minimum time MODULO 666013 (in this case we'd print 4 strings that meet the minimum time; other test case given by default is S = AMYMAMAMY and T = BCDEFGHIJKLNOPQRSTUVWX, there are 214,358,881 distinct strings in this case and you would print 568708);
- -you need to PRINT the lexicographically smallest string that meets the minimum time required (BBTH, AEIOU print BABATIH; AMYMAMAMY, BCDEFGHIJKLNOPQRSTUVWX print ABMNYNMBABMBABMNY)
- TEST CASES:
- https://drive.google.com/drive/folders/1InJAPgNiQCYs4eMCB_nvMokKzk4XliVI - new cases
- https://drive.google.com/drive/folders/1ktgUHnj7Gu-jM_BZRbN09V9NyAkhE5_5 - old cases
- I haven't looked to find the differences between them, maybe they are the same. I only looked at the first 6 (or something) test cases ("solve subtask 1" test cases and I believe they were the same).
- EDITORIAL:
- I'll translate it here:
- -subtask 1: calculate minimum distance between S[i] and S[i + 1] both ways: clockwise and counter clockwise, add the smaller one to the answer (like I did in the code on stackoverflow)
- -subtask 2: *generate two-dimensional array of size 26x26, cost(i, j) = minimum number of steps to get from point i to point j
- *iterate through S and between every S[i], S[i + 1] you iterate through the length of T and find the ideal character R for
- which cost(S[i], R) + cost(R, S[i + 1]) is minimum (there can be multiple characters) (essentially you have a variable ans
- *to which you add "cost(S[i], R) + cost(R, S[i + 1])" when "cost(S[i], R) + cost(R, S[i + 1])" is as small as possible)
- *to find the end answer: either declare "ans = (dh(s[0]) ? 'Z' - s[0] + 1 : s[0] - 'A')" before the loops - or after the
- for loops end "ans += (dh(s[0]) ? 'Z' - s[0] + 1 : s[0] - 'A')";
- *find smallest lexicographic string: always insert smallest character that meets minimum time
- *number of strings that meet min time = product rule or whatever it's called (say position a can take 2 values and position
- b can take 4 values => 8 different possibilities, where in position a & b you put the characters that generate the
- smallest distance)
- TIME COMPLEXITY: O(N * L), where L = 26 (size of alphabet).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement