# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
873168 | tvladm2009 | Baloni (COCI15_baloni) | C++17 | 784 ms | 93540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (!vis[i]) {
h = a[i];
dfs(i);
++ans;
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |