Tuesday, July 15, 2014

Codechef July 2014 Long Contest - CSUB - count substrings solution

Codechef July 2014 Long Contest - CSUB - count substrings: http://www.codechef.com/JULY14/problems/CSUB/

Codechef July 2014 Long Contest - CSUB - count substrings editorial: http://discuss.codechef.com/questions/47237/csub-editorial

Codechef July 2014 Long Contest - CSUB - count substrings solution: http://ideone.com/ET04pJ


#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int t, n;
    long long cnt, r;
    string s;
    scanf("%d", &t);
    while(t--) {
        r=0;
        cnt=0;
        scanf("%d", &n);
        cin>>s;
        for(int i=0; i<s.length(); i++) if(s[i]=='1') cnt++;
        while(cnt>0) r+=cnt, cnt--;
        printf("%lld\n", r);
    }
    return 0;
}


No comments:

Post a Comment