Submission #37138

#TimeUsernameProblemLanguageResultExecution timeMemory
37138chonkaMoney (IZhO17_money)C++98
0 / 100
0 ms13732 KiB
#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)

money.cpp: In function 'void input()':
money.cpp:14:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d" , &n ) ;
                         ^
money.cpp:17:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...