#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 5000+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
vector<queue<int>> closest(MAXN);
vector<int> nxt(MAXN,-1);
bool visited[MAXN];
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
int n;
cin >> n;
vector<int> niz(n);
for(int i=0; i<n; i++)
{
cin >> niz[i];
closest[niz[i]].push(i);
if(!closest[niz[i]+1].empty())
{
nxt[closest[niz[i]+1].front()] = i;
closest[niz[i]+1].pop();
}
}
int rez = 0;
for(int i=0; i<n; i++)
{
if(visited[i])continue;
int br = i;
while(br !=-1)
{
visited[br] = 1;
br = nxt[br];
}
rez++;
}
cout << rez<< endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3676 KB |
Output is correct |
2 |
Correct |
2 ms |
3676 KB |
Output is correct |
3 |
Correct |
2 ms |
3676 KB |
Output is correct |
4 |
Correct |
2 ms |
3676 KB |
Output is correct |
5 |
Runtime error |
20 ms |
20432 KB |
Execution killed with signal 11 |
6 |
Runtime error |
19 ms |
22096 KB |
Execution killed with signal 11 |
7 |
Runtime error |
16 ms |
19544 KB |
Execution killed with signal 11 |
8 |
Runtime error |
20 ms |
19292 KB |
Execution killed with signal 11 |
9 |
Execution timed out |
2094 ms |
10200 KB |
Time limit exceeded |
10 |
Runtime error |
18 ms |
20572 KB |
Execution killed with signal 11 |