Advertisement
Guest User

Circular Problem stackoverflow

a guest
Mar 18th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. INPUT:
  2. C - which subtask to solve
  3. S - string, max length 50000 characters, denotes the blue alphabet letters on the circle
  4. T - string, max length 25 characters, denotes the red letters of the alphabet on the circle
  5.  
  6. Subtask 1:
  7. -uses only string S;
  8. -calculates the minimum time required to print S if the printer starts from 'A' and can go in both directions [(counter)clockwise];
  9.  
  10. Subtask 2:
  11. -uses both strings S and T;
  12. -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);
  13. -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);
  14. -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);
  15. -you need to PRINT the lexicographically smallest string that meets the minimum time required (BBTH, AEIOU print BABATIH; AMYMAMAMY, BCDEFGHIJKLNOPQRSTUVWX print ABMNYNMBABMBABMNY)
  16.  
  17. TEST CASES:
  18. https://drive.google.com/drive/folders/1InJAPgNiQCYs4eMCB_nvMokKzk4XliVI - new cases
  19. https://drive.google.com/drive/folders/1ktgUHnj7Gu-jM_BZRbN09V9NyAkhE5_5 - old cases
  20.  
  21. 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).
  22.  
  23. EDITORIAL:
  24. I'll translate it here:
  25. -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)
  26. -subtask 2: *generate two-dimensional array of size 26x26, cost(i, j) = minimum number of steps to get from point i to point j
  27. *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
  28. which cost(S[i], R) + cost(R, S[i + 1]) is minimum (there can be multiple characters) (essentially you have a variable ans
  29. *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)
  30. *to find the end answer: either declare "ans = (dh(s[0]) ? 'Z' - s[0] + 1 : s[0] - 'A')" before the loops - or after the
  31. for loops end "ans += (dh(s[0]) ? 'Z' - s[0] + 1 : s[0] - 'A')";
  32. *find smallest lexicographic string: always insert smallest character that meets minimum time
  33. *number of strings that meet min time = product rule or whatever it's called (say position a can take 2 values and position
  34. b can take 4 values => 8 different possibilities, where in position a & b you put the characters that generate the
  35. smallest distance)
  36.  
  37. TIME COMPLEXITY: O(N * L), where L = 26 (size of alphabet).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement