1 solutions

  • 0
    @ 2025-12-3 16:44:25

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int t,n,a[8005],b[8005],c[8005];
    int main()
    {
        cin>>t;
        while(t--)
        {
            cin>>n;
            fill(c,c+8004,0);
            fill(a,a+8004,0);
            fill(b,b+8004,0);
            int tmp=0;
            for(int i=1;i<=n;i++)
            {
                cin>>a[i];
                b[i]=b[i-1]+a[i];
                if(i!=1 && b[i]<=8000) c[b[i]]++;         
                for(int j=1;j<i-1;j++)
                {
                    int x=b[i]-b[j];
                    if(x>8000) continue; 
                    c[x]++;
                }
            }
            int ans=0;
            for(int i=1;i<=n;i++)
                if(c[a[i]]!=0) {
    //              cout<<a[i]<<" ";
                    ans++;
                }
            cout<<ans<<endl;
        }
     
        return 0;
    }
    
    • 1

    Information

    ID
    906
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By