Submission #569246

# Submission time Handle Problem Language Result Execution time Memory
569246 2022-05-27T06:39:58 Z knightron0 Izbori (COCI22_izbori) C++14
15 / 110
88 ms 17828 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double

const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif
    int n;
    cin>>n;
    int a[n+2], p[n+2];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        p[i] = -1;
        if(a[i] == 1) p[i] = 1;
    }
    int pref[n+3];
    pref[0] = 0;
    for(int i=1;i<=n;i++){
        pref[i] = pref[i-1] + p[i];
    }
    int ans = 0;
    map<int, int> freq;
    freq[pref[n]]++;
    for(int i=n;i>=1;i--){
        ans += (n-i+1)-freq[pref[i-1]];
        freq[pref[i-1]]++;
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3736 KB Output is correct
2 Correct 18 ms 4768 KB Output is correct
3 Correct 15 ms 2900 KB Output is correct
4 Correct 24 ms 4944 KB Output is correct
5 Correct 21 ms 5076 KB Output is correct
6 Correct 21 ms 5480 KB Output is correct
7 Correct 22 ms 5368 KB Output is correct
8 Correct 22 ms 5372 KB Output is correct
9 Correct 21 ms 5376 KB Output is correct
10 Correct 22 ms 5348 KB Output is correct
11 Correct 88 ms 17828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -