#include<bits/stdc++.h>
using namespace std;
int n,a[1000005],hsh[1000005],cnt=0;
int main()
{
cin >> n;
for(int i=1;i<=n;i++)cin >> a[i];
for(int i=n;i>=1;i--)
{
if(hsh[a[i]-1]==0)
{
++cnt;
}else
{
--hsh[a[i]-1];
}
++hsh[a[i]];
}
printf("%d\n",cnt);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
196 ms |
6992 KB |
Output is correct |
6 |
Correct |
183 ms |
7328 KB |
Output is correct |
7 |
Correct |
167 ms |
5952 KB |
Output is correct |
8 |
Correct |
139 ms |
5852 KB |
Output is correct |
9 |
Correct |
161 ms |
6420 KB |
Output is correct |
10 |
Correct |
174 ms |
6512 KB |
Output is correct |