답안 #118253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118253 2019-06-18T12:53:27 Z songc Lamps (JOI19_lamps) C++14
100 / 100
280 ms 29728 KB
#include <bits/stdc++.h>
using namespace std;

int N;
int A[1010101];
int B[1010101];
int D[1010101][5], ans=1234567890;
int C[5][5] ={
    {0, 1, 1, 2, 2},
    {0, 0, 1, 1, 2},
    {0, 1, 0, 2, 1},
    {0, 0, 1, 0, 2},
    {0, 1, 0, 2, 0}
};

int tog(int p, int o){
    int x = A[p];
    if (o == 1 || o == 4) x = 0;
    else if (o == 2 || o == 3) x = 1;
    return (x != B[p]) ? 1 : 0;
}

int main(){
    scanf("%d", &N);
    for (int i=1; i<=N; i++) scanf("%1d", &A[i]);
    for (int i=1; i<=N; i++) scanf("%1d", &B[i]);
    memset(D, 1, sizeof D);
    D[0][0] = 0;
    for (int i=1; i<=N; i++) for (int j=0; j<5; j++) for (int k=0; k<5; k++) {
        D[i][k] = min(D[i][k], D[i-1][j] + C[j][k] + max(0, tog(i, k)-tog(i-1, j)));
    }
    for (int i=0; i<5; i++) ans = min(ans, D[N][i]);
    printf("%d\n", ans);
    return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
lamp.cpp:25:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i=1; i<=N; i++) scanf("%1d", &A[i]);
                              ~~~~~^~~~~~~~~~~~~~
lamp.cpp:26:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i=1; i<=N; i++) scanf("%1d", &B[i]);
                              ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 20096 KB Output is correct
2 Correct 17 ms 20096 KB Output is correct
3 Correct 16 ms 20088 KB Output is correct
4 Correct 16 ms 20096 KB Output is correct
5 Correct 17 ms 20096 KB Output is correct
6 Correct 16 ms 20096 KB Output is correct
7 Correct 18 ms 20224 KB Output is correct
8 Correct 17 ms 20096 KB Output is correct
9 Correct 18 ms 20096 KB Output is correct
10 Correct 18 ms 20096 KB Output is correct
11 Correct 17 ms 20096 KB Output is correct
12 Correct 16 ms 20068 KB Output is correct
13 Correct 17 ms 20096 KB Output is correct
14 Correct 16 ms 20096 KB Output is correct
15 Correct 16 ms 20096 KB Output is correct
16 Correct 16 ms 20096 KB Output is correct
17 Correct 16 ms 20096 KB Output is correct
18 Correct 17 ms 20096 KB Output is correct
19 Correct 16 ms 20096 KB Output is correct
20 Correct 17 ms 20096 KB Output is correct
21 Correct 16 ms 20096 KB Output is correct
22 Correct 17 ms 20096 KB Output is correct
23 Correct 16 ms 20096 KB Output is correct
24 Correct 17 ms 20096 KB Output is correct
25 Correct 16 ms 20104 KB Output is correct
26 Correct 28 ms 20088 KB Output is correct
27 Correct 18 ms 20144 KB Output is correct
28 Correct 16 ms 20096 KB Output is correct
29 Correct 16 ms 20096 KB Output is correct
30 Correct 17 ms 20096 KB Output is correct
31 Correct 18 ms 20096 KB Output is correct
32 Correct 17 ms 20096 KB Output is correct
33 Correct 17 ms 20096 KB Output is correct
34 Correct 18 ms 20096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 20096 KB Output is correct
2 Correct 17 ms 20096 KB Output is correct
3 Correct 16 ms 20088 KB Output is correct
4 Correct 16 ms 20096 KB Output is correct
5 Correct 17 ms 20096 KB Output is correct
6 Correct 16 ms 20096 KB Output is correct
7 Correct 18 ms 20224 KB Output is correct
8 Correct 17 ms 20096 KB Output is correct
9 Correct 18 ms 20096 KB Output is correct
10 Correct 18 ms 20096 KB Output is correct
11 Correct 17 ms 20096 KB Output is correct
12 Correct 16 ms 20068 KB Output is correct
13 Correct 17 ms 20096 KB Output is correct
14 Correct 16 ms 20096 KB Output is correct
15 Correct 16 ms 20096 KB Output is correct
16 Correct 16 ms 20096 KB Output is correct
17 Correct 16 ms 20096 KB Output is correct
18 Correct 17 ms 20096 KB Output is correct
19 Correct 16 ms 20096 KB Output is correct
20 Correct 17 ms 20096 KB Output is correct
21 Correct 16 ms 20096 KB Output is correct
22 Correct 17 ms 20096 KB Output is correct
23 Correct 16 ms 20096 KB Output is correct
24 Correct 17 ms 20096 KB Output is correct
25 Correct 16 ms 20104 KB Output is correct
26 Correct 28 ms 20088 KB Output is correct
27 Correct 18 ms 20144 KB Output is correct
28 Correct 16 ms 20096 KB Output is correct
29 Correct 16 ms 20096 KB Output is correct
30 Correct 17 ms 20096 KB Output is correct
31 Correct 18 ms 20096 KB Output is correct
32 Correct 17 ms 20096 KB Output is correct
33 Correct 17 ms 20096 KB Output is correct
34 Correct 18 ms 20096 KB Output is correct
35 Correct 18 ms 20096 KB Output is correct
36 Correct 18 ms 20224 KB Output is correct
37 Correct 18 ms 20068 KB Output is correct
38 Correct 18 ms 20096 KB Output is correct
39 Correct 18 ms 20096 KB Output is correct
40 Correct 18 ms 20088 KB Output is correct
41 Correct 18 ms 20096 KB Output is correct
42 Correct 19 ms 20096 KB Output is correct
43 Correct 16 ms 20096 KB Output is correct
44 Correct 17 ms 20096 KB Output is correct
45 Correct 18 ms 20060 KB Output is correct
46 Correct 17 ms 20096 KB Output is correct
47 Correct 17 ms 20224 KB Output is correct
48 Correct 18 ms 20224 KB Output is correct
49 Correct 17 ms 20068 KB Output is correct
50 Correct 17 ms 20096 KB Output is correct
51 Correct 17 ms 20096 KB Output is correct
52 Correct 17 ms 20096 KB Output is correct
53 Correct 17 ms 20092 KB Output is correct
54 Correct 17 ms 20096 KB Output is correct
55 Correct 18 ms 20096 KB Output is correct
56 Correct 17 ms 20096 KB Output is correct
57 Correct 17 ms 20216 KB Output is correct
58 Correct 17 ms 20124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 20140 KB Output is correct
2 Correct 18 ms 20068 KB Output is correct
3 Correct 18 ms 20096 KB Output is correct
4 Correct 18 ms 20096 KB Output is correct
5 Correct 17 ms 20096 KB Output is correct
6 Correct 17 ms 20096 KB Output is correct
7 Correct 280 ms 29668 KB Output is correct
8 Correct 245 ms 29560 KB Output is correct
9 Correct 244 ms 29688 KB Output is correct
10 Correct 237 ms 29672 KB Output is correct
11 Correct 238 ms 29560 KB Output is correct
12 Correct 247 ms 29712 KB Output is correct
13 Correct 248 ms 29496 KB Output is correct
14 Correct 245 ms 29628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 20096 KB Output is correct
2 Correct 17 ms 20096 KB Output is correct
3 Correct 16 ms 20088 KB Output is correct
4 Correct 16 ms 20096 KB Output is correct
5 Correct 17 ms 20096 KB Output is correct
6 Correct 16 ms 20096 KB Output is correct
7 Correct 18 ms 20224 KB Output is correct
8 Correct 17 ms 20096 KB Output is correct
9 Correct 18 ms 20096 KB Output is correct
10 Correct 18 ms 20096 KB Output is correct
11 Correct 17 ms 20096 KB Output is correct
12 Correct 16 ms 20068 KB Output is correct
13 Correct 17 ms 20096 KB Output is correct
14 Correct 16 ms 20096 KB Output is correct
15 Correct 16 ms 20096 KB Output is correct
16 Correct 16 ms 20096 KB Output is correct
17 Correct 16 ms 20096 KB Output is correct
18 Correct 17 ms 20096 KB Output is correct
19 Correct 16 ms 20096 KB Output is correct
20 Correct 17 ms 20096 KB Output is correct
21 Correct 16 ms 20096 KB Output is correct
22 Correct 17 ms 20096 KB Output is correct
23 Correct 16 ms 20096 KB Output is correct
24 Correct 17 ms 20096 KB Output is correct
25 Correct 16 ms 20104 KB Output is correct
26 Correct 28 ms 20088 KB Output is correct
27 Correct 18 ms 20144 KB Output is correct
28 Correct 16 ms 20096 KB Output is correct
29 Correct 16 ms 20096 KB Output is correct
30 Correct 17 ms 20096 KB Output is correct
31 Correct 18 ms 20096 KB Output is correct
32 Correct 17 ms 20096 KB Output is correct
33 Correct 17 ms 20096 KB Output is correct
34 Correct 18 ms 20096 KB Output is correct
35 Correct 18 ms 20096 KB Output is correct
36 Correct 18 ms 20224 KB Output is correct
37 Correct 18 ms 20068 KB Output is correct
38 Correct 18 ms 20096 KB Output is correct
39 Correct 18 ms 20096 KB Output is correct
40 Correct 18 ms 20088 KB Output is correct
41 Correct 18 ms 20096 KB Output is correct
42 Correct 19 ms 20096 KB Output is correct
43 Correct 16 ms 20096 KB Output is correct
44 Correct 17 ms 20096 KB Output is correct
45 Correct 18 ms 20060 KB Output is correct
46 Correct 17 ms 20096 KB Output is correct
47 Correct 17 ms 20224 KB Output is correct
48 Correct 18 ms 20224 KB Output is correct
49 Correct 17 ms 20068 KB Output is correct
50 Correct 17 ms 20096 KB Output is correct
51 Correct 17 ms 20096 KB Output is correct
52 Correct 17 ms 20096 KB Output is correct
53 Correct 17 ms 20092 KB Output is correct
54 Correct 17 ms 20096 KB Output is correct
55 Correct 18 ms 20096 KB Output is correct
56 Correct 17 ms 20096 KB Output is correct
57 Correct 17 ms 20216 KB Output is correct
58 Correct 17 ms 20124 KB Output is correct
59 Correct 19 ms 20140 KB Output is correct
60 Correct 18 ms 20068 KB Output is correct
61 Correct 18 ms 20096 KB Output is correct
62 Correct 18 ms 20096 KB Output is correct
63 Correct 17 ms 20096 KB Output is correct
64 Correct 17 ms 20096 KB Output is correct
65 Correct 280 ms 29668 KB Output is correct
66 Correct 245 ms 29560 KB Output is correct
67 Correct 244 ms 29688 KB Output is correct
68 Correct 237 ms 29672 KB Output is correct
69 Correct 238 ms 29560 KB Output is correct
70 Correct 247 ms 29712 KB Output is correct
71 Correct 248 ms 29496 KB Output is correct
72 Correct 245 ms 29628 KB Output is correct
73 Correct 245 ms 29688 KB Output is correct
74 Correct 243 ms 29524 KB Output is correct
75 Correct 243 ms 29532 KB Output is correct
76 Correct 244 ms 29460 KB Output is correct
77 Correct 243 ms 29560 KB Output is correct
78 Correct 246 ms 29692 KB Output is correct
79 Correct 246 ms 29648 KB Output is correct
80 Correct 242 ms 29560 KB Output is correct
81 Correct 258 ms 29688 KB Output is correct
82 Correct 243 ms 29532 KB Output is correct
83 Correct 248 ms 29560 KB Output is correct
84 Correct 252 ms 29728 KB Output is correct
85 Correct 259 ms 29620 KB Output is correct
86 Correct 259 ms 29492 KB Output is correct
87 Correct 246 ms 29552 KB Output is correct
88 Correct 244 ms 29560 KB Output is correct
89 Correct 251 ms 29640 KB Output is correct
90 Correct 260 ms 29624 KB Output is correct
91 Correct 249 ms 29560 KB Output is correct
92 Correct 249 ms 29584 KB Output is correct
93 Correct 246 ms 29688 KB Output is correct
94 Correct 250 ms 29636 KB Output is correct
95 Correct 244 ms 29684 KB Output is correct
96 Correct 244 ms 29564 KB Output is correct
97 Correct 243 ms 29560 KB Output is correct
98 Correct 244 ms 29652 KB Output is correct
99 Correct 244 ms 29560 KB Output is correct
100 Correct 245 ms 29560 KB Output is correct
101 Correct 245 ms 29676 KB Output is correct
102 Correct 245 ms 29560 KB Output is correct