<script>
const solve_util = (s, c, x, y, z, w) => {
let ans = 0;
for
(let i = 0; i < s.length; i += 4) {
if
(s[i] != x)
ans += c[i];
if
(i + 1 < s.length
&& s[i + 1] != y)
ans += c[i + 1];
if
(i + 2 < s.length
&& s[i + 2] != z)
ans += c[i + 2];
if
(i + 3 < s.length
&& s[i + 3] != w)
ans += c[i + 3];
}
return
ans;
}
const solve_util2 = (s, c, x, y) => {
let ans = 0;
if
(s[0] != x)
ans += c[0];
if
(s[1] != y)
ans += c[1];
return
ans;
}
const minOperations = (N, S, C) => {
if
(S.length == 2) {
let x = solve_util2(S, C,
'0'
,
'1'
);
let y = solve_util2(S, C,
'1'
,
'0'
);
let z = solve_util2(S, C,
'1'
,
'1'
);
let w = solve_util2(S, C,
'0'
,
'0'
);
document.write(`${x},${y},${z},${w}`);
return
Math.min(...[x, y, z, w]);
}
let x = solve_util(S, C,
'0'
,
'1'
,
'0'
,
'1'
);
let y = solve_util(S, C,
'1'
,
'0'
,
'1'
,
'0'
);
let z = solve_util(S, C,
'1'
,
'1'
,
'0'
,
'0'
);
let w = solve_util(S, C,
'0'
,
'0'
,
'1'
,
'1'
);
return
Math.min(...[x, y, z, w]);
}
let N = 4;
let s =
"1011"
;
let ct = [1, 2, 1, 3];
document.write(minOperations(N, s, ct));
</script>