답안 #107137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107137 2019-04-22T07:18:11 Z hamzqq9 Lamps (JOI19_lamps) C++14
100 / 100
142 ms 43520 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000009
#define MOD 1000000007
#define N 1000005
#define M 100000
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;

int n;
int dp[N][5][2];
char a[N],b[N];

void tr(int ind,int sit,int fp) {

	for(int fl=0;fl<2;fl++) {

		int fc=(fp && !fl);

		if(sit<4) {

			umin(dp[ind][sit][fp],dp[ind-1][sit][fl]+fc);
			umin(dp[ind][sit][fp],dp[ind-1][3-sit][fl]+fc+(sit&1));

			if(!(sit&1)) umin(dp[ind][sit][fp],dp[ind-1][4][fl]+fc+1);

		}
		else {

			for(int j=0;j<5;j++) umin(dp[ind][sit][fp],dp[ind-1][j][fl]+fc);

		}

	}

}

int main() {

	scanf("%d",&n);

	scanf("%s %s",a+1,b+1);

	for(int i=0;i<=n;i++) {

		for(int j=0;j<5;j++) {

			for(int k=0;k<2;k++) {

				dp[i][j][k]=inf;

			}

		}

	}

	dp[0][4][0]=0;

	for(int i=1;i<=n;i++) {

		for(int j=0;j<2;j++) tr(i,j,b[i]-'0');

		for(int j=2;j<4;j++) tr(i,j,1-b[i]+'0');

		tr(i,4,a[i]!=b[i]);

	}

	int ans=inf;

	for(int i=0;i<5;i++) for(int j=0;j<2;j++) umin(ans,dp[n][i][j]);

	printf("%d",ans);

}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
lamp.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s %s",a+1,b+1);
  ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 380 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 3 ms 480 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 142 ms 43256 KB Output is correct
8 Correct 99 ms 43520 KB Output is correct
9 Correct 102 ms 43384 KB Output is correct
10 Correct 95 ms 43388 KB Output is correct
11 Correct 100 ms 43312 KB Output is correct
12 Correct 122 ms 43384 KB Output is correct
13 Correct 92 ms 43420 KB Output is correct
14 Correct 93 ms 43420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 380 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 3 ms 480 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 2 ms 384 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 2 ms 384 KB Output is correct
61 Correct 2 ms 384 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 3 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 142 ms 43256 KB Output is correct
66 Correct 99 ms 43520 KB Output is correct
67 Correct 102 ms 43384 KB Output is correct
68 Correct 95 ms 43388 KB Output is correct
69 Correct 100 ms 43312 KB Output is correct
70 Correct 122 ms 43384 KB Output is correct
71 Correct 92 ms 43420 KB Output is correct
72 Correct 93 ms 43420 KB Output is correct
73 Correct 92 ms 43380 KB Output is correct
74 Correct 113 ms 43424 KB Output is correct
75 Correct 87 ms 43516 KB Output is correct
76 Correct 94 ms 43384 KB Output is correct
77 Correct 103 ms 43396 KB Output is correct
78 Correct 108 ms 43428 KB Output is correct
79 Correct 90 ms 43480 KB Output is correct
80 Correct 85 ms 43384 KB Output is correct
81 Correct 98 ms 43384 KB Output is correct
82 Correct 100 ms 43384 KB Output is correct
83 Correct 114 ms 43424 KB Output is correct
84 Correct 103 ms 43456 KB Output is correct
85 Correct 104 ms 43384 KB Output is correct
86 Correct 129 ms 43384 KB Output is correct
87 Correct 102 ms 43520 KB Output is correct
88 Correct 106 ms 43444 KB Output is correct
89 Correct 106 ms 43424 KB Output is correct
90 Correct 104 ms 43488 KB Output is correct
91 Correct 104 ms 43516 KB Output is correct
92 Correct 128 ms 43432 KB Output is correct
93 Correct 88 ms 43428 KB Output is correct
94 Correct 89 ms 43384 KB Output is correct
95 Correct 98 ms 43392 KB Output is correct
96 Correct 102 ms 43420 KB Output is correct
97 Correct 105 ms 43428 KB Output is correct
98 Correct 89 ms 43512 KB Output is correct
99 Correct 97 ms 43512 KB Output is correct
100 Correct 120 ms 43420 KB Output is correct
101 Correct 88 ms 43512 KB Output is correct
102 Correct 102 ms 43512 KB Output is correct