답안 #873178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873178 2023-11-14T15:11:19 Z tvladm2009 Baloni (COCI15_baloni) C++17
20 / 100
772 ms 96956 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e6 + 7;

int n;
int a[N];
bool vis[N];
set<int> s[N];
int h = 0;

int get_nxt(int pos, int val) {
    pos++;
    auto it = s[val].lower_bound(pos);
    if (it == s[val].end()) {
        return -1;
    }
    s[val].erase(it);
    return *it;
}

void dfs(int i) {
    vis[i] = 1;
    --h;
    int j = get_nxt(i, h);
    if (h == 0) {
        return;
    }
    if (j == -1) {
        j = i;
        --h;
    }
    if (h == 0) {
        return;
    }
    dfs(j);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        s[a[i]].insert(i);
    }
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 1);
    sort(ord.begin(), ord.end(), [&](int x, int y) {
        return a[x] > a[y];
    });
    int ans = 0;
    for (auto i : ord) {
        if (!vis[i]) {
            h = a[i];
            dfs(i);
            ++ans;
        }
    }
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 49756 KB Output isn't correct
2 Incorrect 11 ms 49756 KB Output isn't correct
3 Incorrect 12 ms 50012 KB Output isn't correct
4 Incorrect 12 ms 50012 KB Output isn't correct
5 Correct 645 ms 92160 KB Output is correct
6 Incorrect 772 ms 96956 KB Output isn't correct
7 Incorrect 558 ms 88916 KB Output isn't correct
8 Incorrect 581 ms 88572 KB Output isn't correct
9 Correct 633 ms 90748 KB Output is correct
10 Incorrect 668 ms 92232 KB Output isn't correct