Submission #696679

# Submission time Handle Problem Language Result Execution time Memory
696679 2023-02-07T03:33:47 Z Hiennoob123 Izbori (COCI22_izbori) C++14
15 / 110
76 ms 14328 KB
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n;
ll A[200005];
map<ll,ll> idx;
map<ll,bool> nen;
ll cnt[200005];
void solve_all()
{
    ll ans = 0;
    for(int i = 1; i<= n; i++)
    {
        ll sum = 0, Max = 0;
        for(int j = 1; j<= n; j++) cnt[j] = 0;
        for(int j = i; j>= 1; j--)
        {
            cnt[A[j]]++;
            sum++;
            Max = max(Max, cnt[A[j]]);
            if(Max*2>sum)
            {
                //cout << j << " " << i << '\n';
                ans++;
            }
        }
    }
    cout << ans;
}
void solve()
{
    cin >> n;
    for(int i = 1; i<= n; i++)
    {
        cin >> A[i];
        nen[A[i]] = 1;
    }
    ll current = 0;
    for(auto u: nen)
    {
        current++;
        idx[u.fi] = current;
    }
    for(int i = 1; i<= n; i++)
    {
        A[i] = idx[A[i]];
        if(A[i]>2)
        {
            solve_all();
            return;
        }
    }
    map<ll,ll> M;
    M[0] = 1;
    ll cur = 0;
    ll ans = 0;
    for(int i = 1; i<= n; i++)
    {
        if(A[i]==1) cur++;
        else cur--;
        ans += M[cur];
        M[cur]++;
    }
    cout << (n*(n+1)/2)-ans;
}
int main()
{
    ios_base::sync_with_stdio(NULL) ; cin.tie(nullptr) ; cout.tie(nullptr);
    //freopen("B.inp","r",stdin);
    ll test_case = 1;
    while(test_case--)
    {
        solve();
    }
}

# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1380 KB Output is correct
2 Correct 19 ms 1696 KB Output is correct
3 Correct 16 ms 1140 KB Output is correct
4 Correct 21 ms 1772 KB Output is correct
5 Correct 18 ms 1748 KB Output is correct
6 Correct 22 ms 1840 KB Output is correct
7 Correct 28 ms 1812 KB Output is correct
8 Correct 20 ms 1876 KB Output is correct
9 Correct 20 ms 1908 KB Output is correct
10 Correct 19 ms 1924 KB Output is correct
11 Correct 76 ms 14328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -