# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
929206 | Karoot | Baloni (COCI15_baloni) | C++17 | 1728 ms | 131072 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
set<int> bals[1000007];
int main(){
scoobydoobydoo();
int n; cin >> n;
set<pair<int, int>> v;
vector<int> val;
for (int i = 0; i < n; i++){
int h; cin >> h;
v.insert({i, h});
if (n <= 5000)val.push_back(h);
bals[h].insert(i);
}
if (n <= 5000){
int sum = 0;
for (int i = 0; i < n; i++){
if (val[i] == -1)continue;
sum++;
int h = val[i]-1;
for (int j = i+1; j < n; j++){
if (h == 0)break;
if (val[j] == h){
val[j] = -1;
h--;
}
}
}
cout << sum << endl;
return 0;
}
int sum = 0;
while (!v.empty()){
sum++;
int h = (*v.begin()).second;
int i = (*v.begin()).first;
v.erase(v.begin());
if (v.empty())break;
if (bals[h-1].empty())break;
auto it = bals[h-1].upper_bound(i);
while (h >= 1 && it != bals[h-1].end()){
auto itr = v.find({*it, h-1});
v.erase(itr);
bals[h-1].erase(it);
i = *it;
h--;
if (bals[h-1].empty())break;
it = bals[h-1].upper_bound(i);
}
}
cout << sum << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |