답안 #887233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887233 2023-12-14T06:28:25 Z vjudge1 Baloni (COCI15_baloni) C++17
40 / 100
100 ms 131072 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];
  stack<int> bs[n+2];
  vi nx(n+1);
  F(i,n) {
    if (!bs[a[i]+1].empty()) {
      nx[bs[a[i]+1].top()] = i;
      bs[a[i]+1].pop();
    }
    bs[a[i]].push(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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 2 ms 3932 KB Output is correct
5 Runtime error 100 ms 131072 KB Execution killed with signal 9
6 Runtime error 100 ms 131072 KB Execution killed with signal 9
7 Runtime error 97 ms 131072 KB Execution killed with signal 9
8 Runtime error 90 ms 131072 KB Execution killed with signal 9
9 Runtime error 97 ms 131072 KB Execution killed with signal 9
10 Runtime error 95 ms 131072 KB Execution killed with signal 9