Submission details
Task:Bittijono
Sender:rottis
Submission time:2026-01-17 16:33:19 +0200
Language:C++ (C++17)
Status:READY
Result:37
Feedback
groupverdictscore
#1ACCEPTED21
#2ACCEPTED16
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 3details
#4ACCEPTED0.00 s1, 3details
#5ACCEPTED0.00 s1, 3details
#6ACCEPTED0.01 s3details
#7ACCEPTED0.01 s2, 3details
#8ACCEPTED0.01 s3details
#9ACCEPTED0.01 s2, 3details
#10ACCEPTED0.01 s2, 3details
#110.01 s3details
#12ACCEPTED0.01 s2, 3details
#13ACCEPTED0.01 s3details
#140.01 s3details
#150.01 s3details
#16ACCEPTED0.00 s1, 2, 3details
#17ACCEPTED0.00 s1, 3details
#18ACCEPTED0.00 s1, 3details
#19ACCEPTED0.01 s3details
#20ACCEPTED0.01 s3details

Code

#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
ll n;
ll a, b;
 
string in;
string target;
 
bool flips[100001];
 
inline ll mini(ll a, ll b) {
    return a < b ? a : b;
}
 
inline ll maxi(ll a, ll b) {
    return a > b ? a : b;
}
 
ll res = 0;
 
int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
 
    cin >> n >> a >> b;
 
    cin >> in >> target;
 
    for (ll i = 0; i < n; i++) {
        flips[i] = in[i] != target[i];
    }
 
    // if b <= a, never flipping a wrong bit is optimal
    // huh? bug in this branch?
    /*if (b <= a) {
        ll bc = 0;
        for (ll i = 0; i < n; i++) {
            if (!flips[i]) continue;
 
            ll j = i;
            while (j < n && flips[j]) j++;
            i = j-1;
            bc++;
        }
 
        cout << b * bc << '\n';
    } else */{
        // now flipping a contiguous section of 1 wrong bit is optimal
        // if a*2 < b then flipping 2 wrong bits is optimal, too
        // if a*n < b then flipping n wrong bits is optimal, too
        ll optimal_wrong_flips = (b-1)/a;
        ll bc = 0;
        ll ac = 0;
        for (ll i = 0; i < n; i++) {
            if (!flips[i]) continue;
            ll j = i;
            bool do_it = false;
again:
            while (j < n && flips[j]) j++;
            // is the non-flipped section small enough to be optimal?
            do_it = false;
            if ((j - i)*a >= b) {
                for (ll off = 0; off <= optimal_wrong_flips; off++) {
                    if (j + off >= n) {
                        do_it = false;
                        break;
                    }

                    if (flips[j+off]) {
                        do_it = true;
                        break;
                    }
                }
            }
            if (do_it && j < n) {
                ll small_flips = 0;
                while (j < n && !flips[j]) {
                    small_flips++;
                    j++;
                }
                if (small_flips * a > b) {
                    bc++;
                } else {
                    ac += small_flips;
                }
                if (j < n) {
                    goto again;
                }
            }
 
            if ((j-i)*a > b) { // one big flip or
                bc++;
            } else {
                ac += j-i; // many small ones?
            }
            i = j-1;
        } 
        //cout << "a: " << ac << ", b: " << bc << '\n';
        cout << a*ac + b*bc << '\n';
    }
 
    return 0;
}

Test details

Test 1 (public)

Group: 1, 3

Verdict: ACCEPTED

input
8 3 5
10110001
01101000

correct output
11

user output
11

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 644 644
0111000100
0000010111

correct output
1932

user output
1932

Test 3

Group: 1, 3

Verdict: ACCEPTED

input
10 493 986
0001110000
0001100001

correct output
986

user output
986

Test 4

Group: 1, 3

Verdict: ACCEPTED

input
10 240 720
1011001110
1000000001

correct output
1200

user output
1200

Test 5

Group: 1, 3

Verdict: ACCEPTED

input
10 3 7
1110111111
0010010101

correct output
15

user output
15

Test 6

Group: 3

Verdict: ACCEPTED

input
100000 1 1000000000
001100110010101001010111000110...

correct output
50252

user output
50252

Test 7

Group: 2, 3

Verdict: ACCEPTED

input
100000 1000000000 1
110010000110110100110110101011...

correct output
25055

user output
25055

Test 8

Group: 3

Verdict: ACCEPTED

input
100000 1000 1000000000
001001101010100000011110000101...

correct output
50001000

user output
50001000

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
100000 1000000000 1000
101010110001010011011011101110...

correct output
24939000

user output
24939000

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
100000 1000000000 1000000000
001000000001000000000010110111...

correct output
25023000000000

user output
25023000000000

Test 11

Group: 3

Verdict:

input
100000 123456789 987654321
100010110100011000001111001110...

correct output
5475678967593

user output
6121851796575

Feedback: Incorrect character on line 1 col 1: expected "5475678967593", got "6121851796575"

Test 12

Group: 2, 3

Verdict: ACCEPTED

input
100000 987654321 123456789
000100110000010110111101111101...

correct output
3071481453531

user output
3071481453531

Test 13

Group: 3

Verdict: ACCEPTED

input
100000 1000000 1000000000
001100110010100011000111101100...

correct output
49916000000

user output
49916000000

Test 14

Group: 3

Verdict:

input
100000 10000000 1000000000
110111101101111110100101011000...

correct output
494930000000

user output
498750000000

Feedback: Incorrect character on line 1 col 3: expected "494930000000", got "498750000000"

Test 15

Group: 3

Verdict:

input
100000 100000000 1000000000
111110000010100011011100110010...

correct output
4547300000000

user output
4943000000000

Feedback: Incorrect character on line 1 col 2: expected "4547300000000", got "4943000000000"

Test 16

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 1 1
1
1

correct output
0

user output
0

Test 17

Group: 1, 3

Verdict: ACCEPTED

input
10 600 800
0000000000
1110111111

correct output
1400

user output
1400

Test 18

Group: 1, 3

Verdict: ACCEPTED

input
10 300 599
1101001010
0011010110

correct output
1198

user output
1198

Test 19

Group: 3

Verdict: ACCEPTED

input
100000 300000000 500000000
010011101001001010010101101101...

correct output
10000000000000

user output
10000000000000

Test 20

Group: 3

Verdict: ACCEPTED

input
100000 60000 1000000000
110110111011010100001000011011...

correct output
3000000000

user output
3000000000