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

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
89890437 Contestant:
DiabolicPrism
1398C - 12 C++17 (GCC 9-64) Accepted 46 ms 4840 KB 2020-08-14 17:44:17 2020-08-15 07:51:08
→ Source
#include <bits/stdc++.h>
using namespace std;

int t, n;
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    for(int cases = 0; cases < t; cases++)
    {
        cin >> n >> s;
        int cursum = 0;
        map<int, int> cnt;
        cnt[0]++;
        for(int i = 0; i < n; i++)
        {
            cursum += s[i] - '0';
            cnt[cursum - (i + 1)]++;
        }
        long long ans = 0;
        for(auto x : cnt)
        {
            long long have = x.second - 1;
            ans += (have * (have + 1)) / 2;
        }
        cout << ans << "\n";
    }
    return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details