# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37138 | chonka | Money (IZhO17_money) | C++98 | 0 ms | 13732 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<stdio.h>
using namespace std ;
#define MAXN 1000007
int n ;
int a[ MAXN ] ;
int nxt[ MAXN ] ;
int prv[ MAXN ] ;
void input ( ) {
scanf ( "%d" , &n ) ;
int i ;
for ( i = 1 ; i <= n ; i ++ ) {
scanf ( "%d" , &a[ i ] ) ;
}
}
void solve ( ) {
int ans = 0 ;
int i ;
for ( i = 1 ; i <= n ; i ++ ) {
nxt[ i ] = i + 1 ;
prv[ i ] = i - 1 ;
}
for ( i = n ; i >= 1 ; i -- ) {
int j = i - 1 ;
while ( j >= 1 && a[ j ] == prv[ a[ j + 1 ] ] ) { j -- ; }
j ++ ;
prv[ nxt[ a[ i ] ] ] = prv[ a[ j ] ] ;
nxt[ prv[ a[ j ] ] ] = nxt[ a[ i ] ] ;
i = j ;
ans ++ ;
}
printf ( "%d\n" , ans ) ;
}
int main ( ) {
input ( ) ;
solve ( ) ;
return 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |