Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Explain the end part of 466C

Revision en1, by icode_247, 2018-09-12 17:18:05

Hi, So i tried to solve this problem . And i did understand the first part of the tutorialbut got a little confused at the end. It says that I have to add everything from cnt[0] to cnt[n-1] to get my answer. But to get a faster result they did a different workaround. They created sums[] and worked on it. This is the c++ solution. Now, why would they do this?:

 for(int i = n-2 ; i >= 0 ; --i)
            cnt[i] += cnt[i+1];

and in this :

        for(int i = 0 ; i+2 < n ; ++i) {
            ss += a[i];
            if (ss == s)
                ans += cnt[i+2];
        }

Why i+2?.

Tags #c++, 466c, #dp

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English icode_247 2018-09-12 17:18:05 816 Initial revision (published)