Submission #37138

# Submission time Handle Problem Language Result Execution time Memory
37138 2017-12-21T15:29:46 Z chonka Money (IZhO17_money) C++
0 / 100
0 ms 13732 KB
#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

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 time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Incorrect 0 ms 13732 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Incorrect 0 ms 13732 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Incorrect 0 ms 13732 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Incorrect 0 ms 13732 KB Output isn't correct
8 Halted 0 ms 0 KB -