Submission #235252

# Submission time Handle Problem Language Result Execution time Memory
235252 2020-05-27T14:09:55 Z Nodir_Bobiev Lamps (JOI19_lamps) C++17
47 / 100
1000 ms 74696 KB
    /*
    +----------------------------------------------------------------+
    | In the name of Allah, the most Gracious and the most Merciful. |
    +----------------------------------------------------------------+
    Our hearts quake with fear of you
    Our hearts wake with love for you
    And to Islam we must be true
    In everything we think and do.
    --------------------------------
    When your heart is breaking
    And your pain makes you fall
    Remember just remember
    Allah Sees it all.
    */
    # include <bits/stdc++.h>
    # define FILE
    using namespace std;
     
    const int N = 1e6 + 100;
    const int inf = 1e9;
    string A,B;
    int n;
    vector < vector < int > > dp[N];
     
    char op(int x, char c){
        if( x == 0 ) return c;
        if( x == 1 ) return '0';
        if( x == 2 ) return '1';
        if( c == '1' ) return '0';
        return '1';
    }
     
    int main(){
        # ifdef FILEs
            freopen( "input.txt", "r", stdin );
            freopen( "output.txt", "w", stdout );
        # endif
        ios_base::sync_with_stdio(false);
        cin >> n >> A >> B;
        A = '0' + A;
        B = '0' + B;
     
        dp[0].push_back({0,0,0,0});
     
        for( int i = 1; i <= n; i ++ ){
            for( int a = 0; a < 4; a ++ ){
                for( int b = 0; b < 4; b ++ ){
                    for( int c = 0; c < 4; c ++ ){
                        if( op(c,op(b,op(a,A[i]))) != B[i] )
                            continue;
                        int mn = inf;
                        for( auto vc: dp[i-1] ){
                            int cost = vc[3] + (vc[0]!=a && a) + 
                                               (vc[1]!=b && b) + 
                                               (vc[2]!=c && c);
                            mn = min(mn, cost);
                        }
                        if( mn < inf )
                            dp[i].push_back({a,b,c,mn});
                    }
                }
            }
        }
        int ans = inf;
        for( auto vc: dp[n] )ans = min( ans, vc[3] );
        cout << ans;
    }
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 20 ms 23808 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 20 ms 23936 KB Output is correct
6 Correct 18 ms 23808 KB Output is correct
7 Correct 21 ms 23808 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 19 ms 23808 KB Output is correct
10 Correct 19 ms 23936 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 19 ms 23936 KB Output is correct
13 Correct 19 ms 23808 KB Output is correct
14 Correct 20 ms 23936 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23808 KB Output is correct
18 Correct 22 ms 23808 KB Output is correct
19 Correct 19 ms 23808 KB Output is correct
20 Correct 20 ms 23936 KB Output is correct
21 Correct 22 ms 23808 KB Output is correct
22 Correct 20 ms 23808 KB Output is correct
23 Correct 22 ms 23808 KB Output is correct
24 Correct 19 ms 23808 KB Output is correct
25 Correct 20 ms 23936 KB Output is correct
26 Correct 19 ms 23808 KB Output is correct
27 Correct 21 ms 23808 KB Output is correct
28 Correct 23 ms 23880 KB Output is correct
29 Correct 21 ms 23936 KB Output is correct
30 Correct 20 ms 23808 KB Output is correct
31 Correct 20 ms 23936 KB Output is correct
32 Correct 19 ms 23808 KB Output is correct
33 Correct 21 ms 23808 KB Output is correct
34 Correct 19 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 20 ms 23808 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 20 ms 23936 KB Output is correct
6 Correct 18 ms 23808 KB Output is correct
7 Correct 21 ms 23808 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 19 ms 23808 KB Output is correct
10 Correct 19 ms 23936 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 19 ms 23936 KB Output is correct
13 Correct 19 ms 23808 KB Output is correct
14 Correct 20 ms 23936 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23808 KB Output is correct
18 Correct 22 ms 23808 KB Output is correct
19 Correct 19 ms 23808 KB Output is correct
20 Correct 20 ms 23936 KB Output is correct
21 Correct 22 ms 23808 KB Output is correct
22 Correct 20 ms 23808 KB Output is correct
23 Correct 22 ms 23808 KB Output is correct
24 Correct 19 ms 23808 KB Output is correct
25 Correct 20 ms 23936 KB Output is correct
26 Correct 19 ms 23808 KB Output is correct
27 Correct 21 ms 23808 KB Output is correct
28 Correct 23 ms 23880 KB Output is correct
29 Correct 21 ms 23936 KB Output is correct
30 Correct 20 ms 23808 KB Output is correct
31 Correct 20 ms 23936 KB Output is correct
32 Correct 19 ms 23808 KB Output is correct
33 Correct 21 ms 23808 KB Output is correct
34 Correct 19 ms 23808 KB Output is correct
35 Correct 97 ms 27512 KB Output is correct
36 Correct 94 ms 27768 KB Output is correct
37 Correct 95 ms 27512 KB Output is correct
38 Correct 96 ms 27512 KB Output is correct
39 Correct 96 ms 27512 KB Output is correct
40 Correct 93 ms 27512 KB Output is correct
41 Correct 96 ms 27472 KB Output is correct
42 Correct 95 ms 27512 KB Output is correct
43 Correct 95 ms 27512 KB Output is correct
44 Correct 94 ms 27512 KB Output is correct
45 Correct 97 ms 27512 KB Output is correct
46 Correct 92 ms 27640 KB Output is correct
47 Correct 103 ms 27540 KB Output is correct
48 Correct 96 ms 27512 KB Output is correct
49 Correct 94 ms 27512 KB Output is correct
50 Correct 106 ms 27512 KB Output is correct
51 Correct 93 ms 27512 KB Output is correct
52 Correct 101 ms 27512 KB Output is correct
53 Correct 97 ms 27512 KB Output is correct
54 Correct 94 ms 27516 KB Output is correct
55 Correct 96 ms 27524 KB Output is correct
56 Correct 102 ms 27512 KB Output is correct
57 Correct 96 ms 27512 KB Output is correct
58 Correct 98 ms 27512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 19 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Execution timed out 1096 ms 74696 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 20 ms 23808 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 20 ms 23936 KB Output is correct
6 Correct 18 ms 23808 KB Output is correct
7 Correct 21 ms 23808 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 19 ms 23808 KB Output is correct
10 Correct 19 ms 23936 KB Output is correct
11 Correct 19 ms 23936 KB Output is correct
12 Correct 19 ms 23936 KB Output is correct
13 Correct 19 ms 23808 KB Output is correct
14 Correct 20 ms 23936 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23808 KB Output is correct
18 Correct 22 ms 23808 KB Output is correct
19 Correct 19 ms 23808 KB Output is correct
20 Correct 20 ms 23936 KB Output is correct
21 Correct 22 ms 23808 KB Output is correct
22 Correct 20 ms 23808 KB Output is correct
23 Correct 22 ms 23808 KB Output is correct
24 Correct 19 ms 23808 KB Output is correct
25 Correct 20 ms 23936 KB Output is correct
26 Correct 19 ms 23808 KB Output is correct
27 Correct 21 ms 23808 KB Output is correct
28 Correct 23 ms 23880 KB Output is correct
29 Correct 21 ms 23936 KB Output is correct
30 Correct 20 ms 23808 KB Output is correct
31 Correct 20 ms 23936 KB Output is correct
32 Correct 19 ms 23808 KB Output is correct
33 Correct 21 ms 23808 KB Output is correct
34 Correct 19 ms 23808 KB Output is correct
35 Correct 97 ms 27512 KB Output is correct
36 Correct 94 ms 27768 KB Output is correct
37 Correct 95 ms 27512 KB Output is correct
38 Correct 96 ms 27512 KB Output is correct
39 Correct 96 ms 27512 KB Output is correct
40 Correct 93 ms 27512 KB Output is correct
41 Correct 96 ms 27472 KB Output is correct
42 Correct 95 ms 27512 KB Output is correct
43 Correct 95 ms 27512 KB Output is correct
44 Correct 94 ms 27512 KB Output is correct
45 Correct 97 ms 27512 KB Output is correct
46 Correct 92 ms 27640 KB Output is correct
47 Correct 103 ms 27540 KB Output is correct
48 Correct 96 ms 27512 KB Output is correct
49 Correct 94 ms 27512 KB Output is correct
50 Correct 106 ms 27512 KB Output is correct
51 Correct 93 ms 27512 KB Output is correct
52 Correct 101 ms 27512 KB Output is correct
53 Correct 97 ms 27512 KB Output is correct
54 Correct 94 ms 27516 KB Output is correct
55 Correct 96 ms 27524 KB Output is correct
56 Correct 102 ms 27512 KB Output is correct
57 Correct 96 ms 27512 KB Output is correct
58 Correct 98 ms 27512 KB Output is correct
59 Correct 19 ms 23808 KB Output is correct
60 Correct 18 ms 23808 KB Output is correct
61 Correct 19 ms 23808 KB Output is correct
62 Correct 19 ms 23808 KB Output is correct
63 Correct 19 ms 23808 KB Output is correct
64 Correct 19 ms 23808 KB Output is correct
65 Execution timed out 1096 ms 74696 KB Time limit exceeded
66 Halted 0 ms 0 KB -