#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
int N;
string s;
ll ans = 1e9;
int dist[1<<20];
queue<int> q;
void S1(){
memset(dist,-1,sizeof(dist));
cin>>s;
int a = 0,b = 0;
for(int i = 0;i<N;i++){
if(s[i] == '1')a |= 1<<i;
}
cin>>s;
for(int i = 0;i<N;i++){
if(s[i] == '1')b |= 1<<i;
}
dist[a] = 0;
q.push(a);
while(!q.empty()){
auto now = q.front();
q.pop();
for(int l = 0;l<N;l++){
int ta = now,tb = now,tc = now;
for(int r = l;r<N;r++){
ta |= 1<<r;
if(tb&(1<<r))tb ^= (1<<r);
tc ^= 1<<r;
if(dist[ta] == -1){
dist[ta] = dist[now]+1;
q.push(ta);
}
if(dist[tb] == -1){
dist[tb] = dist[now]+1;
q.push(tb);
}
if(dist[tc] == -1){
dist[tc] = dist[now]+1;
q.push(tc);
}
}
}
}
cout<<dist[b];
}
void S3(){
string a,b;
cin>>a>>b;
char pre = '0';
int ans = 0;
for(auto &i:b){
if(i == '1'&&pre == '0')ans++;
pre = i;
}
cout<<ans;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
if(N<=18)S1();
else S3();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
227 ms |
4812 KB |
Output is correct |
9 |
Correct |
226 ms |
4948 KB |
Output is correct |
10 |
Correct |
90 ms |
4744 KB |
Output is correct |
11 |
Correct |
87 ms |
4764 KB |
Output is correct |
12 |
Correct |
224 ms |
5032 KB |
Output is correct |
13 |
Correct |
96 ms |
4844 KB |
Output is correct |
14 |
Correct |
236 ms |
5020 KB |
Output is correct |
15 |
Correct |
97 ms |
4820 KB |
Output is correct |
16 |
Correct |
238 ms |
5040 KB |
Output is correct |
17 |
Correct |
93 ms |
4828 KB |
Output is correct |
18 |
Correct |
206 ms |
4992 KB |
Output is correct |
19 |
Correct |
106 ms |
4792 KB |
Output is correct |
20 |
Correct |
210 ms |
5024 KB |
Output is correct |
21 |
Correct |
95 ms |
4704 KB |
Output is correct |
22 |
Correct |
209 ms |
4956 KB |
Output is correct |
23 |
Correct |
100 ms |
4796 KB |
Output is correct |
24 |
Correct |
222 ms |
5004 KB |
Output is correct |
25 |
Correct |
89 ms |
4696 KB |
Output is correct |
26 |
Correct |
224 ms |
5088 KB |
Output is correct |
27 |
Correct |
92 ms |
4784 KB |
Output is correct |
28 |
Correct |
42 ms |
4696 KB |
Output is correct |
29 |
Correct |
223 ms |
4920 KB |
Output is correct |
30 |
Correct |
92 ms |
4700 KB |
Output is correct |
31 |
Correct |
41 ms |
4740 KB |
Output is correct |
32 |
Correct |
215 ms |
5016 KB |
Output is correct |
33 |
Correct |
89 ms |
4696 KB |
Output is correct |
34 |
Correct |
40 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
227 ms |
4812 KB |
Output is correct |
9 |
Correct |
226 ms |
4948 KB |
Output is correct |
10 |
Correct |
90 ms |
4744 KB |
Output is correct |
11 |
Correct |
87 ms |
4764 KB |
Output is correct |
12 |
Correct |
224 ms |
5032 KB |
Output is correct |
13 |
Correct |
96 ms |
4844 KB |
Output is correct |
14 |
Correct |
236 ms |
5020 KB |
Output is correct |
15 |
Correct |
97 ms |
4820 KB |
Output is correct |
16 |
Correct |
238 ms |
5040 KB |
Output is correct |
17 |
Correct |
93 ms |
4828 KB |
Output is correct |
18 |
Correct |
206 ms |
4992 KB |
Output is correct |
19 |
Correct |
106 ms |
4792 KB |
Output is correct |
20 |
Correct |
210 ms |
5024 KB |
Output is correct |
21 |
Correct |
95 ms |
4704 KB |
Output is correct |
22 |
Correct |
209 ms |
4956 KB |
Output is correct |
23 |
Correct |
100 ms |
4796 KB |
Output is correct |
24 |
Correct |
222 ms |
5004 KB |
Output is correct |
25 |
Correct |
89 ms |
4696 KB |
Output is correct |
26 |
Correct |
224 ms |
5088 KB |
Output is correct |
27 |
Correct |
92 ms |
4784 KB |
Output is correct |
28 |
Correct |
42 ms |
4696 KB |
Output is correct |
29 |
Correct |
223 ms |
4920 KB |
Output is correct |
30 |
Correct |
92 ms |
4700 KB |
Output is correct |
31 |
Correct |
41 ms |
4740 KB |
Output is correct |
32 |
Correct |
215 ms |
5016 KB |
Output is correct |
33 |
Correct |
89 ms |
4696 KB |
Output is correct |
34 |
Correct |
40 ms |
4444 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
4 ms |
2808 KB |
Output is correct |
9 |
Correct |
4 ms |
2808 KB |
Output is correct |
10 |
Correct |
4 ms |
2804 KB |
Output is correct |
11 |
Correct |
4 ms |
2808 KB |
Output is correct |
12 |
Correct |
3 ms |
2808 KB |
Output is correct |
13 |
Correct |
4 ms |
2808 KB |
Output is correct |
14 |
Correct |
4 ms |
2804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
227 ms |
4812 KB |
Output is correct |
9 |
Correct |
226 ms |
4948 KB |
Output is correct |
10 |
Correct |
90 ms |
4744 KB |
Output is correct |
11 |
Correct |
87 ms |
4764 KB |
Output is correct |
12 |
Correct |
224 ms |
5032 KB |
Output is correct |
13 |
Correct |
96 ms |
4844 KB |
Output is correct |
14 |
Correct |
236 ms |
5020 KB |
Output is correct |
15 |
Correct |
97 ms |
4820 KB |
Output is correct |
16 |
Correct |
238 ms |
5040 KB |
Output is correct |
17 |
Correct |
93 ms |
4828 KB |
Output is correct |
18 |
Correct |
206 ms |
4992 KB |
Output is correct |
19 |
Correct |
106 ms |
4792 KB |
Output is correct |
20 |
Correct |
210 ms |
5024 KB |
Output is correct |
21 |
Correct |
95 ms |
4704 KB |
Output is correct |
22 |
Correct |
209 ms |
4956 KB |
Output is correct |
23 |
Correct |
100 ms |
4796 KB |
Output is correct |
24 |
Correct |
222 ms |
5004 KB |
Output is correct |
25 |
Correct |
89 ms |
4696 KB |
Output is correct |
26 |
Correct |
224 ms |
5088 KB |
Output is correct |
27 |
Correct |
92 ms |
4784 KB |
Output is correct |
28 |
Correct |
42 ms |
4696 KB |
Output is correct |
29 |
Correct |
223 ms |
4920 KB |
Output is correct |
30 |
Correct |
92 ms |
4700 KB |
Output is correct |
31 |
Correct |
41 ms |
4740 KB |
Output is correct |
32 |
Correct |
215 ms |
5016 KB |
Output is correct |
33 |
Correct |
89 ms |
4696 KB |
Output is correct |
34 |
Correct |
40 ms |
4444 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |