Submission #545097

# Submission time Handle Problem Language Result Execution time Memory
545097 2022-04-03T14:52:15 Z chonka Lamps (JOI19_lamps) C++
4 / 100
12 ms 6336 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;

#define MAXN 1000007

int n ;
string a , b ;

int dp[ MAXN ] ;

void input ( ) {
    cin >> n >> a >> b ;
}

void solve ( ) {
    int diff = 0 ;
    int mn_alt = 3 * MAXN ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        dp[ i ] = MAXN ;
        if ( a[ i - 1 ] == b[ i - 1 ] ) {
            dp[ i ] = min ( dp[ i ] , dp[ i - 1 ] ) ;
        }
        if ( i > 1 && b[ i - 1 ] != b[ i - 2 ] ) {
            ++ mn_alt ;
        }
        dp[ i ] = min ( dp[ i ] , ( mn_alt + 1 ) / 2 ) ;
        
        if ( a[ i - 1 ] != b[ i - 1 ] ) { ++ diff ; }
        else { diff = 0 ; }
        if ( diff > 0 ) {
            dp[ i ] = min ( dp[ i ] , dp[ i - diff ] + 1 ) ;
        }
        mn_alt = min ( mn_alt , 2 * dp[ i - 1 ] + 2 ) ;
    }
    cout << dp[ n ] << "\n" ;
}

int main ( ) {
    //freopen ( "dictionary.in" , "r" , stdin ) ;
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ;
    // cin >> t ;
    while ( t -- ) {
        input ( ) ;
        solve ( ) ;
    }
    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 12 ms 6312 KB Output is correct
8 Correct 10 ms 6248 KB Output is correct
9 Correct 12 ms 6312 KB Output is correct
10 Correct 10 ms 6336 KB Output is correct
11 Correct 9 ms 6280 KB Output is correct
12 Correct 8 ms 6312 KB Output is correct
13 Correct 8 ms 6308 KB Output is correct
14 Correct 9 ms 6312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -