Submission #545109

# Submission time Handle Problem Language Result Execution time Memory
545109 2022-04-03T15:18:45 Z chonka Lamps (JOI19_lamps) C++
100 / 100
48 ms 16012 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;

#define MAXN 1000007

int n ;
string a , b ;

int dp[ MAXN ][ 3 ] ;

int f ( int pos , int type ) {
    int init = a[ pos ] - '0' ;
    if ( type < 2 ) { init = type ; }
    return ( init != ( b[ pos ] - '0' ) ) ;
}

void input ( ) {
    cin >> n >> a >> b ;
    a = '0' + a ;
    b = '0' + b ;
}

void solve ( ) {
    dp[ 0 ][ 0 ] = dp[ 0 ][ 1 ] = 3 * MAXN ;
    dp[ 0 ][ 2 ] = 0 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 0 ; j < 3 ; ++ j ) {
            dp[ i ][ j ] = 3 * MAXN ;
        }
        for ( int j = 0 ; j < 3 ; ++ j ) {
            for ( int t = 0 ; t < 3 ; ++ t ) {
                int aux = dp[ i - 1 ][ j ] ;
                if ( j != t ) {
                    aux += 2 * ( t != 2 ) ;
                }
                if ( f ( i - 1 , j ) != f ( i , t ) ) { ++ aux ; }
                dp[ i ][ t ] = min ( dp[ i ][ t ] , aux ) ;
            }
        }
    }
    int ans = 3 * MAXN ;
    for ( int i = 0 ; i < 3 ; ++ i ) {
        ans = min ( ans , dp[ n ][ i ] ) ;
    }
    cout << ( ans + 1 ) / 2 << "\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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 280 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 328 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 280 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 328 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 328 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 34 ms 13884 KB Output is correct
8 Correct 32 ms 13964 KB Output is correct
9 Correct 33 ms 13988 KB Output is correct
10 Correct 37 ms 13932 KB Output is correct
11 Correct 36 ms 14004 KB Output is correct
12 Correct 43 ms 14004 KB Output is correct
13 Correct 32 ms 13932 KB Output is correct
14 Correct 37 ms 14080 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 280 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 328 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 328 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 34 ms 13884 KB Output is correct
66 Correct 32 ms 13964 KB Output is correct
67 Correct 33 ms 13988 KB Output is correct
68 Correct 37 ms 13932 KB Output is correct
69 Correct 36 ms 14004 KB Output is correct
70 Correct 43 ms 14004 KB Output is correct
71 Correct 32 ms 13932 KB Output is correct
72 Correct 37 ms 14080 KB Output is correct
73 Correct 34 ms 15920 KB Output is correct
74 Correct 35 ms 15900 KB Output is correct
75 Correct 36 ms 15864 KB Output is correct
76 Correct 43 ms 15896 KB Output is correct
77 Correct 33 ms 15960 KB Output is correct
78 Correct 33 ms 15920 KB Output is correct
79 Correct 35 ms 15884 KB Output is correct
80 Correct 39 ms 16012 KB Output is correct
81 Correct 35 ms 15892 KB Output is correct
82 Correct 34 ms 15992 KB Output is correct
83 Correct 36 ms 15924 KB Output is correct
84 Correct 38 ms 15996 KB Output is correct
85 Correct 40 ms 15860 KB Output is correct
86 Correct 40 ms 15856 KB Output is correct
87 Correct 38 ms 15856 KB Output is correct
88 Correct 36 ms 15856 KB Output is correct
89 Correct 39 ms 15964 KB Output is correct
90 Correct 47 ms 15984 KB Output is correct
91 Correct 45 ms 15928 KB Output is correct
92 Correct 40 ms 15856 KB Output is correct
93 Correct 41 ms 15856 KB Output is correct
94 Correct 41 ms 15860 KB Output is correct
95 Correct 45 ms 15868 KB Output is correct
96 Correct 44 ms 15908 KB Output is correct
97 Correct 43 ms 15868 KB Output is correct
98 Correct 43 ms 15852 KB Output is correct
99 Correct 43 ms 15872 KB Output is correct
100 Correct 44 ms 15940 KB Output is correct
101 Correct 48 ms 15928 KB Output is correct
102 Correct 45 ms 15956 KB Output is correct