제출 #1267269

#제출 시각아이디문제언어결과실행 시간메모리
1267269ngunguoi45Baloni (COCI15_baloni)C++17
60 / 100
33 ms3908 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6+5; int n; int a[maxn]; namespace sub1 { int ans = 0; int vis[5005]; bool check () { return (n <= 5000); } void solve () { for (int i = 1;i <= n; i++) { bool found = 0; for (int j = 1;j < i; j++) { if (a[i]+1 == a[j] && !vis[j]) { found = 1; vis[j] = 1; break; } } ans += (1^found); } cout << ans << "\n"; } } namespace sub2 { int ans = 0; int cnt[maxn]; void solve () { for (int i = 1;i <= n; i++) { if (cnt[a[i]+1] > 0) { cnt[a[i]+1]--; } else { ans++; } cnt[a[i]]++; } cout << ans << "\n"; } } void read_and_prep() { cin >> n; for (int i = 1;i <= n; i++) cin >> a[i]; } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); read_and_prep(); if (sub1::check()) sub1::solve(); sub2::solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...