답안 #483178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483178 2021-10-28T04:06:38 Z daongocha Lamps (JOI19_lamps) C++14
100 / 100
173 ms 54292 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000005;
int dp[MAXN][13];
int cost[13][13];
int turn[2][13];

signed main() {
    int n; cin >> n;
    string s, t;
    cin >> s >> t;
    s = "0" + s; t = "0" + t;
    for (char &c: s) c -= '0';
    for (char &c: t) c -= '0';
    memset(dp, 0x3f, sizeof dp);
    

    
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 13; j++) {
            int v = i;
            if (j == 0) v = 1;
            else if (j == 1) v = 0;
            else if (j == 2) v = 1;
            else if (j == 3) v = 0;
            else if (j == 4) v = 0;
            else if (j == 5) v = 1;
            else if (j == 6) v = 0;
            else if (j == 7) v = 1;
            else if (j == 9) v = 0;
            else if (j == 10) v = 1;
            else if (j == 11) v ^= 1;
            turn[i][j] = v;
        }

    // i = 0 => 01
    // i = 1 => 10
    // i = 2 => 02
    // i = 3 => 20
    // i = 4 => 12
    // i = 5 => 21
    // i = 6 => 00
    // i = 7 => 11
    // i = 8 => 22
    // i = 9 => 0
    // i = 10 => 1
    // i = 11 => 2
    // i = 12 => none

    for (int i = 0; i < 12; i++)
        for (int j = 0; j < 12; j++) {
            if (i == j) continue;
            bool i0 = (i == 0 || i == 1 || i == 2 || i == 3 || i == 6 || i == 9);
            bool i1 = (i == 0 || i == 1 || i == 4 || i == 5 || i == 7 || i == 10);
            bool i2 = (i == 2 || i == 3 || i == 4 || i == 5 || i == 8 || i == 11);
            
            bool j0 = (j == 0 || j == 1 || j == 2 || j == 3 || j == 6 || j == 9);
            bool j1 = (j == 0 || j == 1 || j == 4 || j == 5 || j == 7 || j == 10);
            bool j2 = (j == 2 || j == 3 || j == 4 || j == 5 || j == 8 || j == 11);
            
            cost[i][j] = 2;
            if (i0 && j0) cost[i][j] = 1;
            if (i1 && j1) cost[i][j] = 1;
            if (i2 && j2) cost[i][j] = 1;
            
            if (i0 && j == 9) cost[i][j] = 0;
            else if (i1 && j == 10) cost[i][j] = 0;
            else if (i2 && j == 11) cost[i][j] = 0;
        }
    
    for (int j = 0; j < 13; j++) {
        if (j >= 12) cost[12][j] = 0;
        else if (j >= 9) cost[12][j] = 1;
        else cost[12][j] = 2;
    }
    
    dp[0][12] = 0;
    
    s += (char)0; t += (char)0;
    
    
    int mn = 1e9;
    for (int i = 1; i <= n + 1; i++) {
        for (int msk = 0; msk < 13; msk++) {
            char c = s[i];
            c = turn[c][msk];
            
            dp[i][msk] = 1e9;
            
            if (c == t[i]) {
                for (int pre = 0; pre < 13; pre++) 
                    dp[i][msk] = min(dp[i][msk], dp[i - 1][pre] + cost[pre][msk]);
            }
        }
    }

    cout << dp[n + 1][12];
}  

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:89:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   89 |             c = turn[c][msk];
      |                      ^
lamp.cpp:85:9: warning: unused variable 'mn' [-Wunused-variable]
   85 |     int mn = 1e9;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 51148 KB Output is correct
2 Correct 17 ms 51160 KB Output is correct
3 Correct 17 ms 51180 KB Output is correct
4 Correct 19 ms 51068 KB Output is correct
5 Correct 19 ms 51084 KB Output is correct
6 Correct 19 ms 51096 KB Output is correct
7 Correct 18 ms 51076 KB Output is correct
8 Correct 18 ms 51104 KB Output is correct
9 Correct 20 ms 51084 KB Output is correct
10 Correct 17 ms 51148 KB Output is correct
11 Correct 20 ms 51148 KB Output is correct
12 Correct 17 ms 51128 KB Output is correct
13 Correct 20 ms 51148 KB Output is correct
14 Correct 18 ms 51104 KB Output is correct
15 Correct 20 ms 51148 KB Output is correct
16 Correct 18 ms 51092 KB Output is correct
17 Correct 19 ms 51148 KB Output is correct
18 Correct 17 ms 51060 KB Output is correct
19 Correct 17 ms 51148 KB Output is correct
20 Correct 19 ms 51148 KB Output is correct
21 Correct 21 ms 51060 KB Output is correct
22 Correct 18 ms 51148 KB Output is correct
23 Correct 17 ms 51076 KB Output is correct
24 Correct 20 ms 51164 KB Output is correct
25 Correct 18 ms 51156 KB Output is correct
26 Correct 17 ms 51076 KB Output is correct
27 Correct 20 ms 51108 KB Output is correct
28 Correct 17 ms 51124 KB Output is correct
29 Correct 20 ms 51108 KB Output is correct
30 Correct 17 ms 51148 KB Output is correct
31 Correct 18 ms 51176 KB Output is correct
32 Correct 18 ms 51100 KB Output is correct
33 Correct 22 ms 51104 KB Output is correct
34 Correct 19 ms 51144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 51148 KB Output is correct
2 Correct 17 ms 51160 KB Output is correct
3 Correct 17 ms 51180 KB Output is correct
4 Correct 19 ms 51068 KB Output is correct
5 Correct 19 ms 51084 KB Output is correct
6 Correct 19 ms 51096 KB Output is correct
7 Correct 18 ms 51076 KB Output is correct
8 Correct 18 ms 51104 KB Output is correct
9 Correct 20 ms 51084 KB Output is correct
10 Correct 17 ms 51148 KB Output is correct
11 Correct 20 ms 51148 KB Output is correct
12 Correct 17 ms 51128 KB Output is correct
13 Correct 20 ms 51148 KB Output is correct
14 Correct 18 ms 51104 KB Output is correct
15 Correct 20 ms 51148 KB Output is correct
16 Correct 18 ms 51092 KB Output is correct
17 Correct 19 ms 51148 KB Output is correct
18 Correct 17 ms 51060 KB Output is correct
19 Correct 17 ms 51148 KB Output is correct
20 Correct 19 ms 51148 KB Output is correct
21 Correct 21 ms 51060 KB Output is correct
22 Correct 18 ms 51148 KB Output is correct
23 Correct 17 ms 51076 KB Output is correct
24 Correct 20 ms 51164 KB Output is correct
25 Correct 18 ms 51156 KB Output is correct
26 Correct 17 ms 51076 KB Output is correct
27 Correct 20 ms 51108 KB Output is correct
28 Correct 17 ms 51124 KB Output is correct
29 Correct 20 ms 51108 KB Output is correct
30 Correct 17 ms 51148 KB Output is correct
31 Correct 18 ms 51176 KB Output is correct
32 Correct 18 ms 51100 KB Output is correct
33 Correct 22 ms 51104 KB Output is correct
34 Correct 19 ms 51144 KB Output is correct
35 Correct 20 ms 51080 KB Output is correct
36 Correct 18 ms 51076 KB Output is correct
37 Correct 19 ms 51148 KB Output is correct
38 Correct 18 ms 51148 KB Output is correct
39 Correct 19 ms 51104 KB Output is correct
40 Correct 18 ms 51072 KB Output is correct
41 Correct 17 ms 51148 KB Output is correct
42 Correct 19 ms 51148 KB Output is correct
43 Correct 19 ms 51156 KB Output is correct
44 Correct 19 ms 51124 KB Output is correct
45 Correct 20 ms 51148 KB Output is correct
46 Correct 20 ms 51148 KB Output is correct
47 Correct 19 ms 51140 KB Output is correct
48 Correct 19 ms 51164 KB Output is correct
49 Correct 19 ms 51120 KB Output is correct
50 Correct 18 ms 51168 KB Output is correct
51 Correct 18 ms 51188 KB Output is correct
52 Correct 18 ms 51100 KB Output is correct
53 Correct 19 ms 51132 KB Output is correct
54 Correct 19 ms 51152 KB Output is correct
55 Correct 18 ms 51088 KB Output is correct
56 Correct 18 ms 51080 KB Output is correct
57 Correct 18 ms 51084 KB Output is correct
58 Correct 18 ms 51188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 51148 KB Output is correct
2 Correct 18 ms 51068 KB Output is correct
3 Correct 19 ms 51152 KB Output is correct
4 Correct 18 ms 51112 KB Output is correct
5 Correct 17 ms 51056 KB Output is correct
6 Correct 22 ms 51140 KB Output is correct
7 Correct 166 ms 54116 KB Output is correct
8 Correct 159 ms 54100 KB Output is correct
9 Correct 157 ms 54048 KB Output is correct
10 Correct 158 ms 54088 KB Output is correct
11 Correct 166 ms 54136 KB Output is correct
12 Correct 153 ms 54108 KB Output is correct
13 Correct 157 ms 54096 KB Output is correct
14 Correct 160 ms 54076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 51148 KB Output is correct
2 Correct 17 ms 51160 KB Output is correct
3 Correct 17 ms 51180 KB Output is correct
4 Correct 19 ms 51068 KB Output is correct
5 Correct 19 ms 51084 KB Output is correct
6 Correct 19 ms 51096 KB Output is correct
7 Correct 18 ms 51076 KB Output is correct
8 Correct 18 ms 51104 KB Output is correct
9 Correct 20 ms 51084 KB Output is correct
10 Correct 17 ms 51148 KB Output is correct
11 Correct 20 ms 51148 KB Output is correct
12 Correct 17 ms 51128 KB Output is correct
13 Correct 20 ms 51148 KB Output is correct
14 Correct 18 ms 51104 KB Output is correct
15 Correct 20 ms 51148 KB Output is correct
16 Correct 18 ms 51092 KB Output is correct
17 Correct 19 ms 51148 KB Output is correct
18 Correct 17 ms 51060 KB Output is correct
19 Correct 17 ms 51148 KB Output is correct
20 Correct 19 ms 51148 KB Output is correct
21 Correct 21 ms 51060 KB Output is correct
22 Correct 18 ms 51148 KB Output is correct
23 Correct 17 ms 51076 KB Output is correct
24 Correct 20 ms 51164 KB Output is correct
25 Correct 18 ms 51156 KB Output is correct
26 Correct 17 ms 51076 KB Output is correct
27 Correct 20 ms 51108 KB Output is correct
28 Correct 17 ms 51124 KB Output is correct
29 Correct 20 ms 51108 KB Output is correct
30 Correct 17 ms 51148 KB Output is correct
31 Correct 18 ms 51176 KB Output is correct
32 Correct 18 ms 51100 KB Output is correct
33 Correct 22 ms 51104 KB Output is correct
34 Correct 19 ms 51144 KB Output is correct
35 Correct 20 ms 51080 KB Output is correct
36 Correct 18 ms 51076 KB Output is correct
37 Correct 19 ms 51148 KB Output is correct
38 Correct 18 ms 51148 KB Output is correct
39 Correct 19 ms 51104 KB Output is correct
40 Correct 18 ms 51072 KB Output is correct
41 Correct 17 ms 51148 KB Output is correct
42 Correct 19 ms 51148 KB Output is correct
43 Correct 19 ms 51156 KB Output is correct
44 Correct 19 ms 51124 KB Output is correct
45 Correct 20 ms 51148 KB Output is correct
46 Correct 20 ms 51148 KB Output is correct
47 Correct 19 ms 51140 KB Output is correct
48 Correct 19 ms 51164 KB Output is correct
49 Correct 19 ms 51120 KB Output is correct
50 Correct 18 ms 51168 KB Output is correct
51 Correct 18 ms 51188 KB Output is correct
52 Correct 18 ms 51100 KB Output is correct
53 Correct 19 ms 51132 KB Output is correct
54 Correct 19 ms 51152 KB Output is correct
55 Correct 18 ms 51088 KB Output is correct
56 Correct 18 ms 51080 KB Output is correct
57 Correct 18 ms 51084 KB Output is correct
58 Correct 18 ms 51188 KB Output is correct
59 Correct 18 ms 51148 KB Output is correct
60 Correct 18 ms 51068 KB Output is correct
61 Correct 19 ms 51152 KB Output is correct
62 Correct 18 ms 51112 KB Output is correct
63 Correct 17 ms 51056 KB Output is correct
64 Correct 22 ms 51140 KB Output is correct
65 Correct 166 ms 54116 KB Output is correct
66 Correct 159 ms 54100 KB Output is correct
67 Correct 157 ms 54048 KB Output is correct
68 Correct 158 ms 54088 KB Output is correct
69 Correct 166 ms 54136 KB Output is correct
70 Correct 153 ms 54108 KB Output is correct
71 Correct 157 ms 54096 KB Output is correct
72 Correct 160 ms 54076 KB Output is correct
73 Correct 167 ms 54124 KB Output is correct
74 Correct 161 ms 54076 KB Output is correct
75 Correct 156 ms 54084 KB Output is correct
76 Correct 162 ms 54184 KB Output is correct
77 Correct 162 ms 54088 KB Output is correct
78 Correct 164 ms 54076 KB Output is correct
79 Correct 161 ms 54112 KB Output is correct
80 Correct 162 ms 54184 KB Output is correct
81 Correct 162 ms 54072 KB Output is correct
82 Correct 164 ms 54108 KB Output is correct
83 Correct 167 ms 54076 KB Output is correct
84 Correct 164 ms 54184 KB Output is correct
85 Correct 159 ms 54072 KB Output is correct
86 Correct 161 ms 54060 KB Output is correct
87 Correct 160 ms 54104 KB Output is correct
88 Correct 163 ms 54072 KB Output is correct
89 Correct 161 ms 54108 KB Output is correct
90 Correct 161 ms 54112 KB Output is correct
91 Correct 173 ms 54128 KB Output is correct
92 Correct 170 ms 54292 KB Output is correct
93 Correct 166 ms 54112 KB Output is correct
94 Correct 168 ms 54072 KB Output is correct
95 Correct 165 ms 54140 KB Output is correct
96 Correct 165 ms 54112 KB Output is correct
97 Correct 166 ms 54120 KB Output is correct
98 Correct 166 ms 54072 KB Output is correct
99 Correct 172 ms 54260 KB Output is correct
100 Correct 167 ms 54124 KB Output is correct
101 Correct 165 ms 54072 KB Output is correct
102 Correct 166 ms 54104 KB Output is correct