Submission #796786

# Submission time Handle Problem Language Result Execution time Memory
796786 2023-07-28T18:12:07 Z vjudge1 Lamps (JOI19_lamps) C++14
100 / 100
65 ms 25992 KB
#include<bits/stdc++.h>
using namespace std ;
const int N = 1e6 ;
int n, dp[N + 1][3][2], ans = 1e9 ;
char a[N + 1], b[N + 1] ;
int main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n ;
    for(int i = 1 ; i <= n ; i++)
        cin >> a[i] ;
    for(int i = 1 ; i <= n ; i++)
        cin >> b[i] ;
    for(int i = 0 ; i <= N ; i++)
        for(int j = 0 ; j < 3 ; j++)
            for(int q = 0 ; q < 2 ; q++)
                dp[i][j][q] = 1e9 ;
    dp[0][0][0] = 0 ;
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 0 ; j < 3 ; j++)
            for(int q = 0 ; q < 2 ; q++)
                dp[i][0][0] = min(dp[i][0][0], dp[i - 1][j][q]) ;
        dp[i][0][1] = min({dp[i - 1][1][0] + 1, dp[i - 1][2][0] + 1, dp[i - 1][1][1], dp[i - 1][2][1], dp[i - 1][0][0] + 1, dp[i - 1][0][1]}) ;
        dp[i][1][0] = min({dp[i - 1][1][0], dp[i - 1][2][0] + 1, dp[i - 1][0][0] + 1, dp[i - 1][1][1], dp[i - 1][2][1] + 1, dp[i - 1][0][1] + 1}) ;
        dp[i][2][0] = min({dp[i - 1][2][0], dp[i - 1][1][0] + 1, dp[i - 1][0][0] + 1, dp[i - 1][2][1], dp[i - 1][1][1] + 1, dp[i - 1][0][1] + 1}) ;
        dp[i][1][1] = min({dp[i - 1][2][0] + 2, dp[i - 1][1][0] + 1, dp[i - 1][0][0] + 2, dp[i - 1][2][1] + 1, dp[i - 1][1][1], dp[i - 1][0][1] + 1}) ;
        dp[i][2][1] = min({dp[i - 1][1][0] + 2, dp[i - 1][2][0] + 1, dp[i - 1][0][0] + 2, dp[i - 1][1][1] + 1, dp[i - 1][2][1], dp[i - 1][0][1] + 1}) ;
        for(int j = 0 ; j < 3 ; j++)
            for(int q = 0 ; q < 2 ; q++)
            {
                int num = (a[i] - '0') ;
                if(j == 1)num = 1 ;
                if(j == 2)num = 0 ;
                if(q == 1)num ^= 1 ;
                if(num != b[i] - '0')
                    dp[i][j][q] = 1e9 ;
            }
    }
    for(int j = 0 ; j < 3 ; j++)
        for(int q = 0 ; q < 2 ; q++)
            ans = min(ans, dp[n][j][q]) ;
    cout << ans ;
    return 0 ;
}
//dp[i][j][q]
//j = 0 есди сейчас мы не пользовались первым или вторым видом операций
//j = 1 если сейчас мы сделали на каком то отрезке присваение числу 1
//j = 2 если сейчас мы сделали на каком то отрезке присваение числу 0
//q = 0 если сейчас мы не делаем xor на отрезке в данный момент
//q = 1 если сейчас мы делаем xor на отрезке в данный момент
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 12 ms 23756 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23704 KB Output is correct
5 Correct 10 ms 23760 KB Output is correct
6 Correct 10 ms 23788 KB Output is correct
7 Correct 11 ms 23752 KB Output is correct
8 Correct 10 ms 23804 KB Output is correct
9 Correct 13 ms 23728 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 13 ms 23748 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 9 ms 23816 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23748 KB Output is correct
16 Correct 10 ms 23796 KB Output is correct
17 Correct 10 ms 23748 KB Output is correct
18 Correct 10 ms 23744 KB Output is correct
19 Correct 10 ms 23752 KB Output is correct
20 Correct 12 ms 23784 KB Output is correct
21 Correct 14 ms 23732 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 10 ms 23764 KB Output is correct
24 Correct 12 ms 23744 KB Output is correct
25 Correct 11 ms 23784 KB Output is correct
26 Correct 12 ms 23700 KB Output is correct
27 Correct 10 ms 23780 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 11 ms 23768 KB Output is correct
30 Correct 10 ms 23748 KB Output is correct
31 Correct 10 ms 23764 KB Output is correct
32 Correct 10 ms 23724 KB Output is correct
33 Correct 11 ms 23776 KB Output is correct
34 Correct 11 ms 23720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 12 ms 23756 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23704 KB Output is correct
5 Correct 10 ms 23760 KB Output is correct
6 Correct 10 ms 23788 KB Output is correct
7 Correct 11 ms 23752 KB Output is correct
8 Correct 10 ms 23804 KB Output is correct
9 Correct 13 ms 23728 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 13 ms 23748 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 9 ms 23816 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23748 KB Output is correct
16 Correct 10 ms 23796 KB Output is correct
17 Correct 10 ms 23748 KB Output is correct
18 Correct 10 ms 23744 KB Output is correct
19 Correct 10 ms 23752 KB Output is correct
20 Correct 12 ms 23784 KB Output is correct
21 Correct 14 ms 23732 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 10 ms 23764 KB Output is correct
24 Correct 12 ms 23744 KB Output is correct
25 Correct 11 ms 23784 KB Output is correct
26 Correct 12 ms 23700 KB Output is correct
27 Correct 10 ms 23780 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 11 ms 23768 KB Output is correct
30 Correct 10 ms 23748 KB Output is correct
31 Correct 10 ms 23764 KB Output is correct
32 Correct 10 ms 23724 KB Output is correct
33 Correct 11 ms 23776 KB Output is correct
34 Correct 11 ms 23720 KB Output is correct
35 Correct 10 ms 23764 KB Output is correct
36 Correct 10 ms 23760 KB Output is correct
37 Correct 9 ms 23764 KB Output is correct
38 Correct 9 ms 23764 KB Output is correct
39 Correct 13 ms 23788 KB Output is correct
40 Correct 11 ms 23756 KB Output is correct
41 Correct 10 ms 23804 KB Output is correct
42 Correct 12 ms 23804 KB Output is correct
43 Correct 13 ms 23752 KB Output is correct
44 Correct 10 ms 23764 KB Output is correct
45 Correct 13 ms 23768 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 11 ms 23800 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23748 KB Output is correct
50 Correct 11 ms 23764 KB Output is correct
51 Correct 11 ms 23816 KB Output is correct
52 Correct 11 ms 23756 KB Output is correct
53 Correct 11 ms 23764 KB Output is correct
54 Correct 11 ms 23764 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 11 ms 23764 KB Output is correct
57 Correct 11 ms 23764 KB Output is correct
58 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23788 KB Output is correct
2 Correct 11 ms 23748 KB Output is correct
3 Correct 11 ms 23752 KB Output is correct
4 Correct 11 ms 23692 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 52 ms 25860 KB Output is correct
8 Correct 51 ms 25788 KB Output is correct
9 Correct 52 ms 25832 KB Output is correct
10 Correct 52 ms 25868 KB Output is correct
11 Correct 53 ms 25876 KB Output is correct
12 Correct 51 ms 25796 KB Output is correct
13 Correct 50 ms 25868 KB Output is correct
14 Correct 51 ms 25812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 12 ms 23756 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23704 KB Output is correct
5 Correct 10 ms 23760 KB Output is correct
6 Correct 10 ms 23788 KB Output is correct
7 Correct 11 ms 23752 KB Output is correct
8 Correct 10 ms 23804 KB Output is correct
9 Correct 13 ms 23728 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 13 ms 23748 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 9 ms 23816 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23748 KB Output is correct
16 Correct 10 ms 23796 KB Output is correct
17 Correct 10 ms 23748 KB Output is correct
18 Correct 10 ms 23744 KB Output is correct
19 Correct 10 ms 23752 KB Output is correct
20 Correct 12 ms 23784 KB Output is correct
21 Correct 14 ms 23732 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 10 ms 23764 KB Output is correct
24 Correct 12 ms 23744 KB Output is correct
25 Correct 11 ms 23784 KB Output is correct
26 Correct 12 ms 23700 KB Output is correct
27 Correct 10 ms 23780 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 11 ms 23768 KB Output is correct
30 Correct 10 ms 23748 KB Output is correct
31 Correct 10 ms 23764 KB Output is correct
32 Correct 10 ms 23724 KB Output is correct
33 Correct 11 ms 23776 KB Output is correct
34 Correct 11 ms 23720 KB Output is correct
35 Correct 10 ms 23764 KB Output is correct
36 Correct 10 ms 23760 KB Output is correct
37 Correct 9 ms 23764 KB Output is correct
38 Correct 9 ms 23764 KB Output is correct
39 Correct 13 ms 23788 KB Output is correct
40 Correct 11 ms 23756 KB Output is correct
41 Correct 10 ms 23804 KB Output is correct
42 Correct 12 ms 23804 KB Output is correct
43 Correct 13 ms 23752 KB Output is correct
44 Correct 10 ms 23764 KB Output is correct
45 Correct 13 ms 23768 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 11 ms 23800 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23748 KB Output is correct
50 Correct 11 ms 23764 KB Output is correct
51 Correct 11 ms 23816 KB Output is correct
52 Correct 11 ms 23756 KB Output is correct
53 Correct 11 ms 23764 KB Output is correct
54 Correct 11 ms 23764 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 11 ms 23764 KB Output is correct
57 Correct 11 ms 23764 KB Output is correct
58 Correct 12 ms 23764 KB Output is correct
59 Correct 11 ms 23788 KB Output is correct
60 Correct 11 ms 23748 KB Output is correct
61 Correct 11 ms 23752 KB Output is correct
62 Correct 11 ms 23692 KB Output is correct
63 Correct 11 ms 23764 KB Output is correct
64 Correct 11 ms 23764 KB Output is correct
65 Correct 52 ms 25860 KB Output is correct
66 Correct 51 ms 25788 KB Output is correct
67 Correct 52 ms 25832 KB Output is correct
68 Correct 52 ms 25868 KB Output is correct
69 Correct 53 ms 25876 KB Output is correct
70 Correct 51 ms 25796 KB Output is correct
71 Correct 50 ms 25868 KB Output is correct
72 Correct 51 ms 25812 KB Output is correct
73 Correct 51 ms 25888 KB Output is correct
74 Correct 50 ms 25804 KB Output is correct
75 Correct 52 ms 25872 KB Output is correct
76 Correct 52 ms 25816 KB Output is correct
77 Correct 51 ms 25872 KB Output is correct
78 Correct 53 ms 25832 KB Output is correct
79 Correct 52 ms 25744 KB Output is correct
80 Correct 57 ms 25932 KB Output is correct
81 Correct 52 ms 25872 KB Output is correct
82 Correct 54 ms 25872 KB Output is correct
83 Correct 55 ms 25872 KB Output is correct
84 Correct 54 ms 25808 KB Output is correct
85 Correct 54 ms 25868 KB Output is correct
86 Correct 55 ms 25804 KB Output is correct
87 Correct 54 ms 25836 KB Output is correct
88 Correct 55 ms 25800 KB Output is correct
89 Correct 54 ms 25872 KB Output is correct
90 Correct 55 ms 25808 KB Output is correct
91 Correct 56 ms 25804 KB Output is correct
92 Correct 58 ms 25852 KB Output is correct
93 Correct 65 ms 25992 KB Output is correct
94 Correct 59 ms 25796 KB Output is correct
95 Correct 59 ms 25804 KB Output is correct
96 Correct 59 ms 25808 KB Output is correct
97 Correct 58 ms 25808 KB Output is correct
98 Correct 60 ms 25864 KB Output is correct
99 Correct 59 ms 25812 KB Output is correct
100 Correct 65 ms 25992 KB Output is correct
101 Correct 59 ms 25772 KB Output is correct
102 Correct 59 ms 25868 KB Output is correct