답안 #528660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528660 2022-02-21T02:11:01 Z Apiram Izbori (COCI22_izbori) C++14
15 / 110
14 ms 5812 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = (int)3e5 +5;

signed main() {
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);
    int n; cin>>n;
    vector<int>v(n);
    bool ok = 0;
    for(auto &z : v) {
        cin>>z;
        if(z == 3)
            ok = 1;
        z = z == 1 ? -1 : 1;
    }
    if(ok) {
        cout << 10; return 0;
    }
    int curr = mxN;
    vector<int>p(4*mxN,0);
    int64_t ans = 0, d = 0;
    for(int i = 0 ; i < n ; i++) {
        if(v[i] == 1) {
            p[++curr]++;
            d += p[curr];
        } else {
            p[curr+1]++;
            d -= p[curr--];
        }
        ans += d;
    }
    p.clear();
    p.resize(4*mxN,0);
    curr = mxN;
    int64_t ans2 = 0;
    d = 0;
    for(int i = 0 ; i < n ; i++) {
        if(v[i] == -1) {
            p[++curr]++;
            d += p[curr];
        } else {
            p[curr+1]++;
            d -= p[curr--];
        }
        ans2 += d;
    }
    cout << ans + ans2;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5452 KB Output is correct
2 Correct 13 ms 5580 KB Output is correct
3 Correct 8 ms 5324 KB Output is correct
4 Correct 12 ms 5708 KB Output is correct
5 Correct 13 ms 5708 KB Output is correct
6 Correct 14 ms 5708 KB Output is correct
7 Correct 14 ms 5768 KB Output is correct
8 Correct 14 ms 5712 KB Output is correct
9 Correct 14 ms 5708 KB Output is correct
10 Correct 14 ms 5812 KB Output is correct
11 Correct 12 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -