#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int len;
int s, t;
const int N = (1 << 19);
int get_num(string s) {
int res = 0;
for(int i = (int)s.size() - 1, pw = 1; i >= 0; i--, pw *= 2) {
if(s[i] == '1') res += pw;
}
return res;
}
vector<int> g1, g2;
int dist[N];
vector<bool> vis(N);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> len;
string s0, t0;
cin >> s0 >> t0;
if(len <= 18) {
s = get_num(s0), t = get_num(t0);
for(int i = 0; i < len; i++) {
int x = 0;
for(int j = i; j < len; j++) {
x |= (1 << j);
g1.push_back(x);
g2.push_back((((1 << len) - 1) ^ x));
}
}
queue<int> q;
q.push(s);
vis[s] = 1;
while(!q.empty()) {
int cur = q.front();
if(cur == t) break;
q.pop();
for(int c : g1) {
int to = (cur | c);
if(!vis[to]) q.push(to), dist[to] = dist[cur] + 1, vis[to] = 1;
to = (cur ^ c);
if(!vis[to]) q.push(to), dist[to] = dist[cur] + 1, vis[to] = 1;
}
for(int c : g2) {
int to = (cur & c);
if(!vis[to]) q.push(to), dist[to] = dist[cur] + 1, vis[to] = 1;
}
}
cout << dist[t];
return 0;
}
int cnt[2];
for(int i = 0; i < len; i++) {
cnt[t0[i] - '0'] += (i == 0 || t0[i - 1] != t0[i]);
}
cout << min(cnt[0], cnt[1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
388 KB |
Output is correct |
8 |
Correct |
124 ms |
1748 KB |
Output is correct |
9 |
Correct |
122 ms |
1808 KB |
Output is correct |
10 |
Correct |
67 ms |
1104 KB |
Output is correct |
11 |
Correct |
55 ms |
1108 KB |
Output is correct |
12 |
Correct |
12 ms |
1712 KB |
Output is correct |
13 |
Correct |
51 ms |
1196 KB |
Output is correct |
14 |
Correct |
24 ms |
1732 KB |
Output is correct |
15 |
Correct |
41 ms |
1180 KB |
Output is correct |
16 |
Correct |
63 ms |
1940 KB |
Output is correct |
17 |
Correct |
47 ms |
1176 KB |
Output is correct |
18 |
Correct |
25 ms |
1868 KB |
Output is correct |
19 |
Correct |
10 ms |
1108 KB |
Output is correct |
20 |
Correct |
91 ms |
1860 KB |
Output is correct |
21 |
Correct |
4 ms |
908 KB |
Output is correct |
22 |
Correct |
22 ms |
1884 KB |
Output is correct |
23 |
Correct |
29 ms |
1144 KB |
Output is correct |
24 |
Correct |
3 ms |
1492 KB |
Output is correct |
25 |
Correct |
2 ms |
980 KB |
Output is correct |
26 |
Correct |
43 ms |
1972 KB |
Output is correct |
27 |
Correct |
19 ms |
1108 KB |
Output is correct |
28 |
Correct |
6 ms |
776 KB |
Output is correct |
29 |
Correct |
88 ms |
1876 KB |
Output is correct |
30 |
Correct |
51 ms |
1136 KB |
Output is correct |
31 |
Correct |
3 ms |
724 KB |
Output is correct |
32 |
Correct |
23 ms |
1944 KB |
Output is correct |
33 |
Correct |
40 ms |
1136 KB |
Output is correct |
34 |
Correct |
18 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
388 KB |
Output is correct |
8 |
Correct |
124 ms |
1748 KB |
Output is correct |
9 |
Correct |
122 ms |
1808 KB |
Output is correct |
10 |
Correct |
67 ms |
1104 KB |
Output is correct |
11 |
Correct |
55 ms |
1108 KB |
Output is correct |
12 |
Correct |
12 ms |
1712 KB |
Output is correct |
13 |
Correct |
51 ms |
1196 KB |
Output is correct |
14 |
Correct |
24 ms |
1732 KB |
Output is correct |
15 |
Correct |
41 ms |
1180 KB |
Output is correct |
16 |
Correct |
63 ms |
1940 KB |
Output is correct |
17 |
Correct |
47 ms |
1176 KB |
Output is correct |
18 |
Correct |
25 ms |
1868 KB |
Output is correct |
19 |
Correct |
10 ms |
1108 KB |
Output is correct |
20 |
Correct |
91 ms |
1860 KB |
Output is correct |
21 |
Correct |
4 ms |
908 KB |
Output is correct |
22 |
Correct |
22 ms |
1884 KB |
Output is correct |
23 |
Correct |
29 ms |
1144 KB |
Output is correct |
24 |
Correct |
3 ms |
1492 KB |
Output is correct |
25 |
Correct |
2 ms |
980 KB |
Output is correct |
26 |
Correct |
43 ms |
1972 KB |
Output is correct |
27 |
Correct |
19 ms |
1108 KB |
Output is correct |
28 |
Correct |
6 ms |
776 KB |
Output is correct |
29 |
Correct |
88 ms |
1876 KB |
Output is correct |
30 |
Correct |
51 ms |
1136 KB |
Output is correct |
31 |
Correct |
3 ms |
724 KB |
Output is correct |
32 |
Correct |
23 ms |
1944 KB |
Output is correct |
33 |
Correct |
40 ms |
1136 KB |
Output is correct |
34 |
Correct |
18 ms |
724 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
388 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
8 ms |
3012 KB |
Output is correct |
8 |
Correct |
6 ms |
2984 KB |
Output is correct |
9 |
Correct |
9 ms |
2988 KB |
Output is correct |
10 |
Correct |
8 ms |
3752 KB |
Output is correct |
11 |
Correct |
8 ms |
3596 KB |
Output is correct |
12 |
Correct |
10 ms |
3540 KB |
Output is correct |
13 |
Correct |
11 ms |
3716 KB |
Output is correct |
14 |
Correct |
7 ms |
3608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
388 KB |
Output is correct |
8 |
Correct |
124 ms |
1748 KB |
Output is correct |
9 |
Correct |
122 ms |
1808 KB |
Output is correct |
10 |
Correct |
67 ms |
1104 KB |
Output is correct |
11 |
Correct |
55 ms |
1108 KB |
Output is correct |
12 |
Correct |
12 ms |
1712 KB |
Output is correct |
13 |
Correct |
51 ms |
1196 KB |
Output is correct |
14 |
Correct |
24 ms |
1732 KB |
Output is correct |
15 |
Correct |
41 ms |
1180 KB |
Output is correct |
16 |
Correct |
63 ms |
1940 KB |
Output is correct |
17 |
Correct |
47 ms |
1176 KB |
Output is correct |
18 |
Correct |
25 ms |
1868 KB |
Output is correct |
19 |
Correct |
10 ms |
1108 KB |
Output is correct |
20 |
Correct |
91 ms |
1860 KB |
Output is correct |
21 |
Correct |
4 ms |
908 KB |
Output is correct |
22 |
Correct |
22 ms |
1884 KB |
Output is correct |
23 |
Correct |
29 ms |
1144 KB |
Output is correct |
24 |
Correct |
3 ms |
1492 KB |
Output is correct |
25 |
Correct |
2 ms |
980 KB |
Output is correct |
26 |
Correct |
43 ms |
1972 KB |
Output is correct |
27 |
Correct |
19 ms |
1108 KB |
Output is correct |
28 |
Correct |
6 ms |
776 KB |
Output is correct |
29 |
Correct |
88 ms |
1876 KB |
Output is correct |
30 |
Correct |
51 ms |
1136 KB |
Output is correct |
31 |
Correct |
3 ms |
724 KB |
Output is correct |
32 |
Correct |
23 ms |
1944 KB |
Output is correct |
33 |
Correct |
40 ms |
1136 KB |
Output is correct |
34 |
Correct |
18 ms |
724 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |