Submission #197170

# Submission time Handle Problem Language Result Execution time Memory
197170 2020-01-19T13:14:28 Z HellAngel Lamps (JOI19_lamps) C++14
100 / 100
106 ms 67276 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int maxn = 1e6 + 6;

/// 0: on
/// 1: off
/// 2: tog
/// 3: on & tog
/// 4: off & tog
/// 5: tog & on
/// 6: tog & off
/// 7: do nothing

int dp[maxn][8];

void Minimize(int &a, const int &b)
{
    a = min(a, b);
}

void Update(int i, int j)
{
    if(j == 0) /// on
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0]);
        dp[i][j] = min(dp[i][j], dp[i - 1][1] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][2] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][3]);
        dp[i][j] = min(dp[i][j], dp[i - 1][4] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][5]);
        dp[i][j] = min(dp[i][j], dp[i - 1][6] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][7] + 1);
    }
    else if(j == 1) /// off
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][1]);
        dp[i][j] = min(dp[i][j], dp[i - 1][2] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][3] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][4]);
        dp[i][j] = min(dp[i][j], dp[i - 1][5] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][6]);
        dp[i][j] = min(dp[i][j], dp[i - 1][7] + 1);
    }
    else if(j == 2) /// tog
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][1] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][2]);
        dp[i][j] = min(dp[i][j], dp[i - 1][3]);
        dp[i][j] = min(dp[i][j], dp[i - 1][4]);
        dp[i][j] = min(dp[i][j], dp[i - 1][5]);
        dp[i][j] = min(dp[i][j], dp[i - 1][6]);
        dp[i][j] = min(dp[i][j], dp[i - 1][7] + 1);
    }
    else if(j == 3) /// on & tog
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][1] + 2);
        dp[i][j] = min(dp[i][j], dp[i - 1][2] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][3]);
        dp[i][j] = min(dp[i][j], dp[i - 1][4] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][5] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][6] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][7] + 2);
    }
    else if(j == 4) /// off & tog
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0] + 2);
        dp[i][j] = min(dp[i][j], dp[i - 1][1] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][2] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][3] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][4]);
        dp[i][j] = min(dp[i][j], dp[i - 1][5] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][6] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][7] + 2);
    }
    else if(j == 5) /// tog & on
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][1] + 2);
        dp[i][j] = min(dp[i][j], dp[i - 1][2] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][3] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][4] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][5]);
        dp[i][j] = min(dp[i][j], dp[i - 1][6] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][7] + 2);
    }
    else if(j == 6) /// tog & off
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0] + 2);
        dp[i][j] = min(dp[i][j], dp[i - 1][1] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][2] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][3] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][4] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][5] + 1);
        dp[i][j] = min(dp[i][j], dp[i - 1][6]);
        dp[i][j] = min(dp[i][j], dp[i - 1][7] + 2);
    }
    else if(j == 7)
    {
        dp[i][j] = min(dp[i][j], dp[i - 1][0]);
        dp[i][j] = min(dp[i][j], dp[i - 1][1]);
        dp[i][j] = min(dp[i][j], dp[i - 1][2]);
        dp[i][j] = min(dp[i][j], dp[i - 1][3]);
        dp[i][j] = min(dp[i][j], dp[i - 1][4]);
        dp[i][j] = min(dp[i][j], dp[i - 1][5]);
        dp[i][j] = min(dp[i][j], dp[i - 1][6]);
        dp[i][j] = min(dp[i][j], dp[i - 1][7]);
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    string s, t;
    int n;
    cin >> n;
    cin >> s >> t;
    fill_n(&dp[0][0], maxn*8, 1e9);
    if(s[0] == '0' && t[0] == '1')
    {
        dp[0][0] = dp[0][2] = 1;
        dp[0][4] = dp[0][5] = 2;
    }
    if(s[0] == '0' && t[0] == '0')
    {
        dp[0][1] = 1;
        dp[0][3] = dp[0][6] = 2;
        dp[0][7] = 0;
    }
    if(s[0] == '1' && t[0] == '0')
    {
        dp[0][1] = dp[0][2] = 1;
        dp[0][3] = dp[0][6] = 2;
    }
    if(s[0] == '1' && t[0] == '1')
    {
        dp[0][0] = 1;
        dp[0][4] = dp[0][5] = 2;
        dp[0][7] = 0;
    }
    for(int i = 1; i < s.length(); i++)
    {
        if(s[i] == '0' && t[i] == '1')
        {
            Update(i, 0);
            Update(i, 2);
            Update(i, 4);
            Update(i, 5);
        }
        if(s[i] == '0' && t[i] == '0')
        {
            Update(i, 1);
            Update(i, 3);
            Update(i, 6);
            Update(i, 7);
        }
        if(s[i] == '1' && t[i] == '1')
        {
            Update(i, 0);
            Update(i, 4);
            Update(i, 5);
            Update(i, 7);
        }
        if(s[i] == '1' && t[i] == '0')
        {
            Update(i, 1);
            Update(i, 2);
            Update(i, 3);
            Update(i, 6);
        }
    }
    int ans = 1e9;
    for(int i = 0; i <= 7; i++)
    {
        ans = min(ans, dp[s.length() - 1][i]);
    }
    cout << ans;
}

Compilation message

lamp.cpp: In function 'int32_t main()':
lamp.cpp:148:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < s.length(); i++)
                    ~~^~~~~~~~~~~~
lamp.cpp:120:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:120:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# Verdict Execution time Memory Grader output
1 Correct 56 ms 63076 KB Output is correct
2 Correct 55 ms 62968 KB Output is correct
3 Correct 55 ms 62968 KB Output is correct
4 Correct 55 ms 62884 KB Output is correct
5 Correct 57 ms 62968 KB Output is correct
6 Correct 55 ms 63060 KB Output is correct
7 Correct 55 ms 62896 KB Output is correct
8 Correct 53 ms 62968 KB Output is correct
9 Correct 55 ms 62968 KB Output is correct
10 Correct 57 ms 62940 KB Output is correct
11 Correct 55 ms 62940 KB Output is correct
12 Correct 54 ms 62988 KB Output is correct
13 Correct 56 ms 62968 KB Output is correct
14 Correct 55 ms 62932 KB Output is correct
15 Correct 55 ms 62968 KB Output is correct
16 Correct 66 ms 62968 KB Output is correct
17 Correct 55 ms 62968 KB Output is correct
18 Correct 55 ms 62940 KB Output is correct
19 Correct 55 ms 62972 KB Output is correct
20 Correct 56 ms 63024 KB Output is correct
21 Correct 55 ms 62884 KB Output is correct
22 Correct 61 ms 62888 KB Output is correct
23 Correct 55 ms 62932 KB Output is correct
24 Correct 55 ms 62968 KB Output is correct
25 Correct 55 ms 62968 KB Output is correct
26 Correct 55 ms 62968 KB Output is correct
27 Correct 55 ms 62940 KB Output is correct
28 Correct 55 ms 62968 KB Output is correct
29 Correct 55 ms 62968 KB Output is correct
30 Correct 56 ms 62948 KB Output is correct
31 Correct 56 ms 62968 KB Output is correct
32 Correct 55 ms 63096 KB Output is correct
33 Correct 55 ms 62940 KB Output is correct
34 Correct 55 ms 63096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 63076 KB Output is correct
2 Correct 55 ms 62968 KB Output is correct
3 Correct 55 ms 62968 KB Output is correct
4 Correct 55 ms 62884 KB Output is correct
5 Correct 57 ms 62968 KB Output is correct
6 Correct 55 ms 63060 KB Output is correct
7 Correct 55 ms 62896 KB Output is correct
8 Correct 53 ms 62968 KB Output is correct
9 Correct 55 ms 62968 KB Output is correct
10 Correct 57 ms 62940 KB Output is correct
11 Correct 55 ms 62940 KB Output is correct
12 Correct 54 ms 62988 KB Output is correct
13 Correct 56 ms 62968 KB Output is correct
14 Correct 55 ms 62932 KB Output is correct
15 Correct 55 ms 62968 KB Output is correct
16 Correct 66 ms 62968 KB Output is correct
17 Correct 55 ms 62968 KB Output is correct
18 Correct 55 ms 62940 KB Output is correct
19 Correct 55 ms 62972 KB Output is correct
20 Correct 56 ms 63024 KB Output is correct
21 Correct 55 ms 62884 KB Output is correct
22 Correct 61 ms 62888 KB Output is correct
23 Correct 55 ms 62932 KB Output is correct
24 Correct 55 ms 62968 KB Output is correct
25 Correct 55 ms 62968 KB Output is correct
26 Correct 55 ms 62968 KB Output is correct
27 Correct 55 ms 62940 KB Output is correct
28 Correct 55 ms 62968 KB Output is correct
29 Correct 55 ms 62968 KB Output is correct
30 Correct 56 ms 62948 KB Output is correct
31 Correct 56 ms 62968 KB Output is correct
32 Correct 55 ms 63096 KB Output is correct
33 Correct 55 ms 62940 KB Output is correct
34 Correct 55 ms 63096 KB Output is correct
35 Correct 55 ms 62984 KB Output is correct
36 Correct 55 ms 62968 KB Output is correct
37 Correct 55 ms 62920 KB Output is correct
38 Correct 56 ms 63100 KB Output is correct
39 Correct 56 ms 62968 KB Output is correct
40 Correct 55 ms 63036 KB Output is correct
41 Correct 61 ms 63096 KB Output is correct
42 Correct 56 ms 62968 KB Output is correct
43 Correct 56 ms 62968 KB Output is correct
44 Correct 55 ms 62940 KB Output is correct
45 Correct 56 ms 62968 KB Output is correct
46 Correct 55 ms 62968 KB Output is correct
47 Correct 55 ms 62968 KB Output is correct
48 Correct 55 ms 62940 KB Output is correct
49 Correct 56 ms 62968 KB Output is correct
50 Correct 55 ms 62968 KB Output is correct
51 Correct 55 ms 62968 KB Output is correct
52 Correct 56 ms 62968 KB Output is correct
53 Correct 56 ms 62932 KB Output is correct
54 Correct 55 ms 62968 KB Output is correct
55 Correct 56 ms 62972 KB Output is correct
56 Correct 64 ms 62940 KB Output is correct
57 Correct 55 ms 62968 KB Output is correct
58 Correct 56 ms 62968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 62884 KB Output is correct
2 Correct 55 ms 63096 KB Output is correct
3 Correct 60 ms 63004 KB Output is correct
4 Correct 66 ms 62972 KB Output is correct
5 Correct 56 ms 63096 KB Output is correct
6 Correct 55 ms 62940 KB Output is correct
7 Correct 91 ms 66888 KB Output is correct
8 Correct 90 ms 67020 KB Output is correct
9 Correct 91 ms 67024 KB Output is correct
10 Correct 91 ms 67060 KB Output is correct
11 Correct 92 ms 67012 KB Output is correct
12 Correct 103 ms 67148 KB Output is correct
13 Correct 104 ms 67016 KB Output is correct
14 Correct 91 ms 67020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 63076 KB Output is correct
2 Correct 55 ms 62968 KB Output is correct
3 Correct 55 ms 62968 KB Output is correct
4 Correct 55 ms 62884 KB Output is correct
5 Correct 57 ms 62968 KB Output is correct
6 Correct 55 ms 63060 KB Output is correct
7 Correct 55 ms 62896 KB Output is correct
8 Correct 53 ms 62968 KB Output is correct
9 Correct 55 ms 62968 KB Output is correct
10 Correct 57 ms 62940 KB Output is correct
11 Correct 55 ms 62940 KB Output is correct
12 Correct 54 ms 62988 KB Output is correct
13 Correct 56 ms 62968 KB Output is correct
14 Correct 55 ms 62932 KB Output is correct
15 Correct 55 ms 62968 KB Output is correct
16 Correct 66 ms 62968 KB Output is correct
17 Correct 55 ms 62968 KB Output is correct
18 Correct 55 ms 62940 KB Output is correct
19 Correct 55 ms 62972 KB Output is correct
20 Correct 56 ms 63024 KB Output is correct
21 Correct 55 ms 62884 KB Output is correct
22 Correct 61 ms 62888 KB Output is correct
23 Correct 55 ms 62932 KB Output is correct
24 Correct 55 ms 62968 KB Output is correct
25 Correct 55 ms 62968 KB Output is correct
26 Correct 55 ms 62968 KB Output is correct
27 Correct 55 ms 62940 KB Output is correct
28 Correct 55 ms 62968 KB Output is correct
29 Correct 55 ms 62968 KB Output is correct
30 Correct 56 ms 62948 KB Output is correct
31 Correct 56 ms 62968 KB Output is correct
32 Correct 55 ms 63096 KB Output is correct
33 Correct 55 ms 62940 KB Output is correct
34 Correct 55 ms 63096 KB Output is correct
35 Correct 55 ms 62984 KB Output is correct
36 Correct 55 ms 62968 KB Output is correct
37 Correct 55 ms 62920 KB Output is correct
38 Correct 56 ms 63100 KB Output is correct
39 Correct 56 ms 62968 KB Output is correct
40 Correct 55 ms 63036 KB Output is correct
41 Correct 61 ms 63096 KB Output is correct
42 Correct 56 ms 62968 KB Output is correct
43 Correct 56 ms 62968 KB Output is correct
44 Correct 55 ms 62940 KB Output is correct
45 Correct 56 ms 62968 KB Output is correct
46 Correct 55 ms 62968 KB Output is correct
47 Correct 55 ms 62968 KB Output is correct
48 Correct 55 ms 62940 KB Output is correct
49 Correct 56 ms 62968 KB Output is correct
50 Correct 55 ms 62968 KB Output is correct
51 Correct 55 ms 62968 KB Output is correct
52 Correct 56 ms 62968 KB Output is correct
53 Correct 56 ms 62932 KB Output is correct
54 Correct 55 ms 62968 KB Output is correct
55 Correct 56 ms 62972 KB Output is correct
56 Correct 64 ms 62940 KB Output is correct
57 Correct 55 ms 62968 KB Output is correct
58 Correct 56 ms 62968 KB Output is correct
59 Correct 56 ms 62884 KB Output is correct
60 Correct 55 ms 63096 KB Output is correct
61 Correct 60 ms 63004 KB Output is correct
62 Correct 66 ms 62972 KB Output is correct
63 Correct 56 ms 63096 KB Output is correct
64 Correct 55 ms 62940 KB Output is correct
65 Correct 91 ms 66888 KB Output is correct
66 Correct 90 ms 67020 KB Output is correct
67 Correct 91 ms 67024 KB Output is correct
68 Correct 91 ms 67060 KB Output is correct
69 Correct 92 ms 67012 KB Output is correct
70 Correct 103 ms 67148 KB Output is correct
71 Correct 104 ms 67016 KB Output is correct
72 Correct 91 ms 67020 KB Output is correct
73 Correct 93 ms 66988 KB Output is correct
74 Correct 94 ms 67036 KB Output is correct
75 Correct 89 ms 67012 KB Output is correct
76 Correct 89 ms 67016 KB Output is correct
77 Correct 91 ms 67020 KB Output is correct
78 Correct 91 ms 67020 KB Output is correct
79 Correct 94 ms 67136 KB Output is correct
80 Correct 96 ms 67044 KB Output is correct
81 Correct 104 ms 67016 KB Output is correct
82 Correct 96 ms 67088 KB Output is correct
83 Correct 105 ms 67020 KB Output is correct
84 Correct 97 ms 67088 KB Output is correct
85 Correct 98 ms 67016 KB Output is correct
86 Correct 98 ms 67016 KB Output is correct
87 Correct 96 ms 67088 KB Output is correct
88 Correct 97 ms 66988 KB Output is correct
89 Correct 97 ms 67016 KB Output is correct
90 Correct 97 ms 67084 KB Output is correct
91 Correct 100 ms 67144 KB Output is correct
92 Correct 98 ms 67148 KB Output is correct
93 Correct 102 ms 66980 KB Output is correct
94 Correct 102 ms 67016 KB Output is correct
95 Correct 102 ms 66988 KB Output is correct
96 Correct 105 ms 67020 KB Output is correct
97 Correct 97 ms 66988 KB Output is correct
98 Correct 102 ms 67020 KB Output is correct
99 Correct 102 ms 67012 KB Output is correct
100 Correct 102 ms 67276 KB Output is correct
101 Correct 102 ms 67016 KB Output is correct
102 Correct 106 ms 67016 KB Output is correct