Submission details
Task:Bittijono
Sender:Lelleri
Submission time:2026-01-17 16:13:13 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 3details
#20.00 s1, 2, 3details
#30.00 s1, 3details
#40.00 s1, 3details
#50.00 s1, 3details
#60.01 s3details
#70.01 s2, 3details
#80.01 s3details
#90.01 s2, 3details
#100.01 s2, 3details
#110.01 s3details
#120.01 s2, 3details
#130.01 s3details
#140.01 s3details
#150.01 s3details
#16ACCEPTED0.00 s1, 2, 3details
#170.00 s1, 3details
#180.00 s1, 3details
#190.01 s3details
#200.01 s3details

Compiler report

input/code.cpp: In function 'std::tuple<int, int, int> get_max_range(std::vector<int>)':
input/code.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < starts.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
input/code.cpp:37:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if(i == starts.size()-1){
      |            ~~^~~~~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FAST ios::sync_with_stdio(0); cin.tie(0);

int n;

tuple<int, int, int> get_max_range(vector<int> values){
    vector<int> pref(n, 0);
    partial_sum(values.begin(), values.end(), pref.begin());

    vector<int> starts;
    int max_sum = 0;
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if(count+values[i] <= values[i]){
            starts.pb(i);
        }
        count = max(count+values[i], values[i]);

        max_sum = max(count, max_sum);
    }

    tuple<int, int, int> max_range = {0, 0, 0};
    for (int i = 0; i < starts.size(); i++)
    {
        int d = max(0, starts[i]-1);
        int b_sum = pref[d];

        int de = 0;
        if(i == starts.size()-1){
            de = n-1;
        }
        else{
            de = starts[i+1]-1;
        }
        int a_sum = pref[de];

        int sum = a_sum-b_sum;

        if(sum > get<2>(max_range)){
            max_range = {d+1, de, sum};
        }
    }
    
    return max_range;
}

int bits_in_range(string st, int s, int e){
    int bits = 0;
    for (int i = n-e-1; i < n-s+1; i++)
    {
        if(st[i] == '1') bits++;
    }
    return bits;
}


int main(){
    
    int a, b;
    cin >> n >> a >> b;

    bitset<8> n1, n2;

    cin >> n1 >> n2;

    int cost = 0;
    while(n1 != n2){
        bitset<8> diff = n1^n2;

        vector<int> values(n);
        for (int i = n-1; i >= 0; i--)
        {
            if(diff[n-1-i]) values[n-1-i] = a;
            else values[n-1-i] = -a;
        }

        tuple<int,int,int> max_range = get_max_range(values);
    
        int c1 = bits_in_range(diff.to_string(), get<0>(max_range), get<1>(max_range)) * a;

        if(get<2>(max_range) > 0 && c1 > b){
            for (int i = get<0>(max_range); i <= get<1>(max_range); i++)
            {
                n2.flip(i);
            }
            cost += b;
        }
        else{
            for (int i = 0; i <= n; i++)
            {
                if(n1[i] && !n2[i]){
                    n2.flip(i);
                    cost += a;
                }
            }
        }

    }


    cout << cost;

    return 0;
}


//3 3 -3 3 3 -3 -3 3

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:

input
10 644 644
0111000100
0000010111

correct output
1932

user output
2576

Feedback: Incorrect character on line 1 col 1: expected "1932", got "2576"

Test 3

Group: 1, 3

Verdict:

input
10 493 986
0001110000
0001100001

correct output
986

user output
1479

Feedback: Incorrect character on line 1 col 1: expected "986", got "1479"

Test 4

Group: 1, 3

Verdict:

input
10 240 720
1011001110
1000000001

correct output
1200

user output
960

Feedback: Incorrect character on line 1 col 1: expected "1200", got "960"

Test 5

Group: 1, 3

Verdict:

input
10 3 7
1110111111
0010010101

correct output
15

user output
(empty)

Error:
terminate called after throwing an instance of 'std::out_of_range'
  what():  bitset::flip: __position (which is 8) >= _Nb (which is 8)

Test 6

Group: 3

Verdict:

input
100000 1 1000000000
001100110010101001010111000110...

correct output
50252

user output
(empty)

Test 7

Group: 2, 3

Verdict:

input
100000 1000000000 1
110010000110110100110110101011...

correct output
25055

user output
(empty)

Test 8

Group: 3

Verdict:

input
100000 1000 1000000000
001001101010100000011110000101...

correct output
50001000

user output
(empty)

Test 9

Group: 2, 3

Verdict:

input
100000 1000000000 1000
101010110001010011011011101110...

correct output
24939000

user output
(empty)

Test 10

Group: 2, 3

Verdict:

input
100000 1000000000 1000000000
001000000001000000000010110111...

correct output
25023000000000

user output
(empty)

Test 11

Group: 3

Verdict:

input
100000 123456789 987654321
100010110100011000001111001110...

correct output
5475678967593

user output
(empty)

Test 12

Group: 2, 3

Verdict:

input
100000 987654321 123456789
000100110000010110111101111101...

correct output
3071481453531

user output
(empty)

Test 13

Group: 3

Verdict:

input
100000 1000000 1000000000
001100110010100011000111101100...

correct output
49916000000

user output
(empty)

Test 14

Group: 3

Verdict:

input
100000 10000000 1000000000
110111101101111110100101011000...

correct output
494930000000

user output
(empty)

Test 15

Group: 3

Verdict:

input
100000 100000000 1000000000
111110000010100011011100110010...

correct output
4547300000000

user output
(empty)

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:

input
10 600 800
0000000000
1110111111

correct output
1400

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1400", got "0"

Test 18

Group: 1, 3

Verdict:

input
10 300 599
1101001010
0011010110

correct output
1198

user output
900

Feedback: Incorrect character on line 1 col 1: expected "1198", got "900"

Test 19

Group: 3

Verdict:

input
100000 300000000 500000000
010011101001001010010101101101...

correct output
10000000000000

user output
(empty)

Test 20

Group: 3

Verdict:

input
100000 60000 1000000000
110110111011010100001000011011...

correct output
3000000000

user output
(empty)