답안 #132629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132629 2019-07-19T08:59:34 Z hamzqq9 Lamps (JOI19_lamps) C++14
100 / 100
144 ms 27836 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ii pair<int,int>
#define ll long long
#define orta ((bas+son)>>1)
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define inf 20000000
#define N 1000005
#define MOD 998244353
#define KOK 700		
using namespace std;

int n;
int dp[N][3][2];
char s[2][N];

int main() {

	scanf("%d",&n);

	for(int i=0;i<2;i++) scanf("%s",s[i]+1);

	// 0 no 1 zero 2 black
	// 0 no 1 toggle

	for(int i=0;i<3;i++) for(int j=0;j<2;j++) dp[0][i][j]=inf;

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

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

		for(int cg=0;cg<3;cg++) {

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

				dp[i+1][cg][tg]=inf;

				for(int c=0;c<3;c++) {

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

						int cost=(c!=cg && cg)+(t!=tg && tg);
						int bit=(cg==1?0:cg==2?1:s[0][i+1]-'0')^tg;

						if(bit==(s[1][i+1]-'0')) umin(dp[i+1][cg][tg],dp[i][c][t]+cost);

					}

				}

			}

		}

	}

	int ans=inf;

	for(int c=0;c<3;c++) {

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

			int bit=(c==1?0:c==2?1:s[0][n]-'0')^t;

			if(bit==(s[1][n]-'0')) umin(ans,dp[n][c][t]);

		}

	}

	printf("%d",ans);
 
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
lamp.cpp:27:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<2;i++) scanf("%s",s[i]+1);
                       ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 380 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 3 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 112 ms 27640 KB Output is correct
8 Correct 113 ms 27768 KB Output is correct
9 Correct 112 ms 27756 KB Output is correct
10 Correct 113 ms 27640 KB Output is correct
11 Correct 111 ms 27640 KB Output is correct
12 Correct 112 ms 27768 KB Output is correct
13 Correct 112 ms 27768 KB Output is correct
14 Correct 112 ms 27836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 380 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 3 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 372 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 112 ms 27640 KB Output is correct
66 Correct 113 ms 27768 KB Output is correct
67 Correct 112 ms 27756 KB Output is correct
68 Correct 113 ms 27640 KB Output is correct
69 Correct 111 ms 27640 KB Output is correct
70 Correct 112 ms 27768 KB Output is correct
71 Correct 112 ms 27768 KB Output is correct
72 Correct 112 ms 27836 KB Output is correct
73 Correct 111 ms 27128 KB Output is correct
74 Correct 123 ms 27104 KB Output is correct
75 Correct 112 ms 27284 KB Output is correct
76 Correct 114 ms 27188 KB Output is correct
77 Correct 113 ms 27248 KB Output is correct
78 Correct 111 ms 27120 KB Output is correct
79 Correct 112 ms 27260 KB Output is correct
80 Correct 111 ms 27188 KB Output is correct
81 Correct 111 ms 27128 KB Output is correct
82 Correct 111 ms 27128 KB Output is correct
83 Correct 116 ms 27128 KB Output is correct
84 Correct 116 ms 27100 KB Output is correct
85 Correct 117 ms 27128 KB Output is correct
86 Correct 117 ms 27168 KB Output is correct
87 Correct 116 ms 27256 KB Output is correct
88 Correct 116 ms 27164 KB Output is correct
89 Correct 118 ms 27136 KB Output is correct
90 Correct 115 ms 27172 KB Output is correct
91 Correct 118 ms 27128 KB Output is correct
92 Correct 119 ms 27256 KB Output is correct
93 Correct 122 ms 27328 KB Output is correct
94 Correct 144 ms 27288 KB Output is correct
95 Correct 123 ms 27144 KB Output is correct
96 Correct 120 ms 27212 KB Output is correct
97 Correct 120 ms 27120 KB Output is correct
98 Correct 120 ms 27100 KB Output is correct
99 Correct 119 ms 27128 KB Output is correct
100 Correct 130 ms 27152 KB Output is correct
101 Correct 121 ms 27256 KB Output is correct
102 Correct 121 ms 27256 KB Output is correct