Submission #570536

# Submission time Handle Problem Language Result Execution time Memory
570536 2022-05-30T11:54:58 Z timreizin Lamps (JOI19_lamps) C++17
0 / 100
1 ms 468 KB
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <set>
#include <array>
#include <algorithm>
#include <cassert>

using namespace std;

using ll = long long;

int counter(string a, string b)
{
    int last = b.front(), cnt = 0, res = 0;
    for (int i = 0; i < a.size(); ++i)
    {
        if (b[i] != last)
        {
            for (int j = i - cnt; j < i; ++j)
            {
                if (a[j] != last)
                {
                    ++res;
                    break;
                }
            }
            cnt = 0;
            last = b[i];
        }
        ++cnt;
    }
    for (int j = (int)a.size() - cnt; j < a.size(); ++j)
    {
        if (a[j] != last)
        {
            ++res;
            break;
        }
    }
    return res;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    string a, b;
    cin >> n >> a >> b;
    int minRes = 1e9;
    for (int mask = 0; mask < (1 << n); ++mask)
    {
        string na = a;
        int add = 0;
        for (int i = 0; i < n; ++i)
        {
            if (mask & (1 << i))
            {
                if (a[i] == '0') na[i] = '1';
                else na[i] = '0';
            }
            if (i > 0) add += !(mask & (1 << i)) && (mask & (1 << (i - 1)));
        }
        minRes = min(minRes, counter(na, b) + add);
    }
    assert(minRes >= counter(a, b));
    cout << minRes;
    return 0;
}

Compilation message

lamp.cpp: In function 'int counter(std::string, std::string)':
lamp.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < a.size(); ++i)
      |                     ~~^~~~~~~~~~
lamp.cpp:34:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int j = (int)a.size() - cnt; j < a.size(); ++j)
      |                                       ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -