답안 #1116776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116776 2024-11-22T11:06:41 Z firewater Lamps (JOI19_lamps) C++14
100 / 100
68 ms 51788 KB
#include<bits/stdc++.h>
#define N 1001000
using namespace std;
int n,ans,a[N],b[N],f[N][5][2];
char s1[N],s2[N];
int main()
 {
 	scanf("%d%s%s",&n,s1+1,s2+1);
	for(int i=1;i<=n;++i)
 		a[i]=s2[i]-'0'+1,b[i]=(s1[i]!=s2[i]);
 	memset(f,127/3,sizeof(f));
    f[0][0][0]=0;
 	for(int i=1;i<=n;++i)
 		for(int j=0;j<=2;++j)
            for(int k=0;k<=1;++k){
                f[i][0][b[i]]=min(f[i][0][b[i]],f[i-1][j][k]+(b[i]&&(b[i]!=k)));
                if(j){
                    f[i][j][k]=min(f[i][j][k],f[i-1][j][k]+(a[i]!=j&&a[i]!=a[i-1]));
                    f[i][j%2+1][!k]=min(f[i][j%2+1][!k],f[i-1][j][k]+(!k)+(a[i]==j&&a[i]==a[i-1]));
                }
                f[i][a[i]][k]=min(f[i][a[i]][k],f[i-1][j][k]+1);
            }
 	ans=f[0][0][1];
 	for(int j=0;j<=2;++j)
        for(int k=0;k<=1;++k)
 	ans=min(ans,f[n][j][k]);
 	printf("%d\n",ans);
 	return 0;
 }

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d%s%s",&n,s1+1,s2+1);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 43344 KB Output is correct
2 Correct 7 ms 43504 KB Output is correct
3 Correct 9 ms 43344 KB Output is correct
4 Correct 10 ms 43344 KB Output is correct
5 Correct 11 ms 43344 KB Output is correct
6 Correct 12 ms 43344 KB Output is correct
7 Correct 16 ms 43464 KB Output is correct
8 Correct 18 ms 43344 KB Output is correct
9 Correct 19 ms 43344 KB Output is correct
10 Correct 19 ms 43380 KB Output is correct
11 Correct 24 ms 43484 KB Output is correct
12 Correct 21 ms 43344 KB Output is correct
13 Correct 17 ms 43344 KB Output is correct
14 Correct 18 ms 43344 KB Output is correct
15 Correct 22 ms 43344 KB Output is correct
16 Correct 21 ms 43344 KB Output is correct
17 Correct 18 ms 43344 KB Output is correct
18 Correct 14 ms 43344 KB Output is correct
19 Correct 15 ms 43344 KB Output is correct
20 Correct 18 ms 43512 KB Output is correct
21 Correct 18 ms 43468 KB Output is correct
22 Correct 21 ms 43408 KB Output is correct
23 Correct 24 ms 43344 KB Output is correct
24 Correct 26 ms 43336 KB Output is correct
25 Correct 20 ms 43344 KB Output is correct
26 Correct 18 ms 43512 KB Output is correct
27 Correct 18 ms 43344 KB Output is correct
28 Correct 16 ms 43356 KB Output is correct
29 Correct 16 ms 43344 KB Output is correct
30 Correct 18 ms 43456 KB Output is correct
31 Correct 19 ms 43344 KB Output is correct
32 Correct 22 ms 43344 KB Output is correct
33 Correct 20 ms 43344 KB Output is correct
34 Correct 16 ms 43344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 43344 KB Output is correct
2 Correct 7 ms 43504 KB Output is correct
3 Correct 9 ms 43344 KB Output is correct
4 Correct 10 ms 43344 KB Output is correct
5 Correct 11 ms 43344 KB Output is correct
6 Correct 12 ms 43344 KB Output is correct
7 Correct 16 ms 43464 KB Output is correct
8 Correct 18 ms 43344 KB Output is correct
9 Correct 19 ms 43344 KB Output is correct
10 Correct 19 ms 43380 KB Output is correct
11 Correct 24 ms 43484 KB Output is correct
12 Correct 21 ms 43344 KB Output is correct
13 Correct 17 ms 43344 KB Output is correct
14 Correct 18 ms 43344 KB Output is correct
15 Correct 22 ms 43344 KB Output is correct
16 Correct 21 ms 43344 KB Output is correct
17 Correct 18 ms 43344 KB Output is correct
18 Correct 14 ms 43344 KB Output is correct
19 Correct 15 ms 43344 KB Output is correct
20 Correct 18 ms 43512 KB Output is correct
21 Correct 18 ms 43468 KB Output is correct
22 Correct 21 ms 43408 KB Output is correct
23 Correct 24 ms 43344 KB Output is correct
24 Correct 26 ms 43336 KB Output is correct
25 Correct 20 ms 43344 KB Output is correct
26 Correct 18 ms 43512 KB Output is correct
27 Correct 18 ms 43344 KB Output is correct
28 Correct 16 ms 43356 KB Output is correct
29 Correct 16 ms 43344 KB Output is correct
30 Correct 18 ms 43456 KB Output is correct
31 Correct 19 ms 43344 KB Output is correct
32 Correct 22 ms 43344 KB Output is correct
33 Correct 20 ms 43344 KB Output is correct
34 Correct 16 ms 43344 KB Output is correct
35 Correct 15 ms 43344 KB Output is correct
36 Correct 15 ms 43380 KB Output is correct
37 Correct 18 ms 43344 KB Output is correct
38 Correct 17 ms 43308 KB Output is correct
39 Correct 16 ms 43344 KB Output is correct
40 Correct 16 ms 43452 KB Output is correct
41 Correct 17 ms 43344 KB Output is correct
42 Correct 19 ms 43344 KB Output is correct
43 Correct 18 ms 43344 KB Output is correct
44 Correct 16 ms 43344 KB Output is correct
45 Correct 19 ms 43336 KB Output is correct
46 Correct 14 ms 43344 KB Output is correct
47 Correct 17 ms 43344 KB Output is correct
48 Correct 16 ms 43344 KB Output is correct
49 Correct 17 ms 43344 KB Output is correct
50 Correct 19 ms 43344 KB Output is correct
51 Correct 22 ms 43344 KB Output is correct
52 Correct 18 ms 43344 KB Output is correct
53 Correct 23 ms 43344 KB Output is correct
54 Correct 23 ms 43344 KB Output is correct
55 Correct 19 ms 43452 KB Output is correct
56 Correct 19 ms 43348 KB Output is correct
57 Correct 14 ms 43372 KB Output is correct
58 Correct 24 ms 43848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 43344 KB Output is correct
2 Correct 19 ms 43324 KB Output is correct
3 Correct 22 ms 43360 KB Output is correct
4 Correct 20 ms 43356 KB Output is correct
5 Correct 20 ms 43356 KB Output is correct
6 Correct 18 ms 43344 KB Output is correct
7 Correct 53 ms 49232 KB Output is correct
8 Correct 53 ms 49232 KB Output is correct
9 Correct 57 ms 49232 KB Output is correct
10 Correct 58 ms 49244 KB Output is correct
11 Correct 55 ms 49228 KB Output is correct
12 Correct 56 ms 49188 KB Output is correct
13 Correct 61 ms 49380 KB Output is correct
14 Correct 58 ms 49232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 43344 KB Output is correct
2 Correct 7 ms 43504 KB Output is correct
3 Correct 9 ms 43344 KB Output is correct
4 Correct 10 ms 43344 KB Output is correct
5 Correct 11 ms 43344 KB Output is correct
6 Correct 12 ms 43344 KB Output is correct
7 Correct 16 ms 43464 KB Output is correct
8 Correct 18 ms 43344 KB Output is correct
9 Correct 19 ms 43344 KB Output is correct
10 Correct 19 ms 43380 KB Output is correct
11 Correct 24 ms 43484 KB Output is correct
12 Correct 21 ms 43344 KB Output is correct
13 Correct 17 ms 43344 KB Output is correct
14 Correct 18 ms 43344 KB Output is correct
15 Correct 22 ms 43344 KB Output is correct
16 Correct 21 ms 43344 KB Output is correct
17 Correct 18 ms 43344 KB Output is correct
18 Correct 14 ms 43344 KB Output is correct
19 Correct 15 ms 43344 KB Output is correct
20 Correct 18 ms 43512 KB Output is correct
21 Correct 18 ms 43468 KB Output is correct
22 Correct 21 ms 43408 KB Output is correct
23 Correct 24 ms 43344 KB Output is correct
24 Correct 26 ms 43336 KB Output is correct
25 Correct 20 ms 43344 KB Output is correct
26 Correct 18 ms 43512 KB Output is correct
27 Correct 18 ms 43344 KB Output is correct
28 Correct 16 ms 43356 KB Output is correct
29 Correct 16 ms 43344 KB Output is correct
30 Correct 18 ms 43456 KB Output is correct
31 Correct 19 ms 43344 KB Output is correct
32 Correct 22 ms 43344 KB Output is correct
33 Correct 20 ms 43344 KB Output is correct
34 Correct 16 ms 43344 KB Output is correct
35 Correct 15 ms 43344 KB Output is correct
36 Correct 15 ms 43380 KB Output is correct
37 Correct 18 ms 43344 KB Output is correct
38 Correct 17 ms 43308 KB Output is correct
39 Correct 16 ms 43344 KB Output is correct
40 Correct 16 ms 43452 KB Output is correct
41 Correct 17 ms 43344 KB Output is correct
42 Correct 19 ms 43344 KB Output is correct
43 Correct 18 ms 43344 KB Output is correct
44 Correct 16 ms 43344 KB Output is correct
45 Correct 19 ms 43336 KB Output is correct
46 Correct 14 ms 43344 KB Output is correct
47 Correct 17 ms 43344 KB Output is correct
48 Correct 16 ms 43344 KB Output is correct
49 Correct 17 ms 43344 KB Output is correct
50 Correct 19 ms 43344 KB Output is correct
51 Correct 22 ms 43344 KB Output is correct
52 Correct 18 ms 43344 KB Output is correct
53 Correct 23 ms 43344 KB Output is correct
54 Correct 23 ms 43344 KB Output is correct
55 Correct 19 ms 43452 KB Output is correct
56 Correct 19 ms 43348 KB Output is correct
57 Correct 14 ms 43372 KB Output is correct
58 Correct 24 ms 43848 KB Output is correct
59 Correct 20 ms 43344 KB Output is correct
60 Correct 19 ms 43324 KB Output is correct
61 Correct 22 ms 43360 KB Output is correct
62 Correct 20 ms 43356 KB Output is correct
63 Correct 20 ms 43356 KB Output is correct
64 Correct 18 ms 43344 KB Output is correct
65 Correct 53 ms 49232 KB Output is correct
66 Correct 53 ms 49232 KB Output is correct
67 Correct 57 ms 49232 KB Output is correct
68 Correct 58 ms 49244 KB Output is correct
69 Correct 55 ms 49228 KB Output is correct
70 Correct 56 ms 49188 KB Output is correct
71 Correct 61 ms 49380 KB Output is correct
72 Correct 58 ms 49232 KB Output is correct
73 Correct 61 ms 51156 KB Output is correct
74 Correct 61 ms 51272 KB Output is correct
75 Correct 65 ms 51244 KB Output is correct
76 Correct 63 ms 51272 KB Output is correct
77 Correct 62 ms 51280 KB Output is correct
78 Correct 54 ms 51280 KB Output is correct
79 Correct 54 ms 51360 KB Output is correct
80 Correct 56 ms 51356 KB Output is correct
81 Correct 55 ms 51272 KB Output is correct
82 Correct 52 ms 51128 KB Output is correct
83 Correct 66 ms 51280 KB Output is correct
84 Correct 68 ms 51148 KB Output is correct
85 Correct 65 ms 51252 KB Output is correct
86 Correct 60 ms 51164 KB Output is correct
87 Correct 60 ms 51164 KB Output is correct
88 Correct 61 ms 51280 KB Output is correct
89 Correct 59 ms 51108 KB Output is correct
90 Correct 57 ms 51272 KB Output is correct
91 Correct 59 ms 51152 KB Output is correct
92 Correct 58 ms 51144 KB Output is correct
93 Correct 54 ms 51272 KB Output is correct
94 Correct 63 ms 51544 KB Output is correct
95 Correct 55 ms 51280 KB Output is correct
96 Correct 58 ms 51192 KB Output is correct
97 Correct 53 ms 51272 KB Output is correct
98 Correct 62 ms 51168 KB Output is correct
99 Correct 56 ms 51280 KB Output is correct
100 Correct 52 ms 51296 KB Output is correct
101 Correct 58 ms 51788 KB Output is correct
102 Correct 57 ms 51168 KB Output is correct