USACO Silver: Subsequences Summing to Sevens

I’m struggling with this question: http://www.usaco.org/index.php?page=viewproblem2&cpid=595.

I don’t understand the USACO Guide’s code solution.

USACO Guide’s Code: https://usaco.guide/solutions/usaco-595?lang=cpp
From what I understand, they loop through each element (O(n)) and create a prefix sum reminder for each element. So at each element, we have the remainder of the sum of the prior elements by 7. I’m not sure what happens next, and I don’t understand the purpose of the vistos set. Please let me know.

Thanks!

The reason they want you to use the modulus of each prefix sum is to reduce all the possible numbers from 0-6. I don’t really think you need that set. What I did was after creating the prefix sum, I looped through 0-6 and found the leftmost and rightmost appearances of that number. The streak for that number is right minus left index. Keep track of the longest streak.