Submission #887239

# Submission time Handle Problem Language Result Execution time Memory
887239 2023-12-14T06:32:26 Z vjudge1 Baloni (COCI15_baloni) C++17
100 / 100
85 ms 44836 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define pb push_back


void solve() {  
  int n;
  cin >> n;
  vi a(n+1);
  F(i,n) cin >> a[i];
  vector<vector<int>> bs(1000002);
  vi nx(n+1);
  F(i,n) {
    if (!bs[a[i]+1].empty()) {
      nx[bs[a[i]+1].back()] = i;
      bs[a[i]+1].pop_back();
    }
    bs[a[i]].push_back(i);
  }
  int c = 0;
  vi vis(n+1,0);
  F(i,n) {
    if (!vis[i]) {
      c++;
      int ptr = i;
      while (nx[ptr]) {
        vis[ptr] = 1;
        ptr = nx[ptr];
      }
      vis[ptr] = 1;
    }
  }
  cout << c << endl;
} 
    
                  
                             
signed main() { 
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifdef Local
  freopen("in","r",stdin);
  freopen("out","w",stdout); 
  #endif
  int t = 1;
  //cin >> t;
	F(i,t) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 23900 KB Output is correct
2 Correct 6 ms 23900 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 7 ms 23900 KB Output is correct
5 Correct 85 ms 42732 KB Output is correct
6 Correct 79 ms 44836 KB Output is correct
7 Correct 76 ms 41156 KB Output is correct
8 Correct 61 ms 40924 KB Output is correct
9 Correct 66 ms 41808 KB Output is correct
10 Correct 68 ms 42784 KB Output is correct