0
For problem C: Store the frequencies of each character in a 2D array freq[][] of size 26*2 (Character in 1st column and it's corresponding frequency in 2nd column. Sort the freq[][] array by frequencies(2nd col). Now there can be 1 <= d <= 26 (N % d == 0) distinct characters. I claim that a sliding window of length 'd' over the freq[][] array will give me the required characters with each character having frequency of N/d. This window will be the one that minimizes the loss. But how to calculate loss? A simple solution will be the in the sliding window match the higher frequency characters with the lower frequency characters and balance out the remaining frequencies. This is due the fact that once we fix a frequency (N/d) we are picking the characters that are close to that frequency. Here is the java submission: https://codeforces.net/contest/1781/submission/308437460 |
Created or updated the text |
Name |
---|