This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
typedef long long ll;
using namespace std;
const int inf = 1e9 + 5, di = 3, cnt = 1 << (2 * di);
void upd(int& a, const int& b) { a = min(a, b); }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string sa, sb;
cin >> n >> sa >> sb;
vector<int> a, b;
for (int i = 0; i < n; i++) a.push_back(sa[i] == '1');
for (int i = 0; i < n; i++) b.push_back(sb[i] == '1');
vector<int> c(cnt), v, num(cnt, -1);
for (int i = 0; i < cnt; i++)
{
int k = 0;
vector<int> f(4);
for (int j = 0; j < di; j++)
{
int val = (i >> (2 * j)) & 3;
if (val) c[i] |= val << (k * 2), k++, f[val]++;
}
if (*max_element(f.begin(), f.end()) <= 1 && c[i] == i)
num[i] = v.size(), v.push_back(i);
}
vector<vector<int> > dp(n + 1, vector<int>(v.size(), inf));
dp[0][0] = 0;
for (int i = 0; i < n; i++)
{
// ideme ukoncit par zmien - naraz vzdy len jednu
for (int j = v.size() - 1; j >= 0; j--) for (int k = 0; k < di; k++)
{
int mask = (cnt - 1) ^ (3 << (2 * k)), nw = num[c[mask & v[j]]];
if (nw != -1) upd(dp[i][nw], dp[i][j]);
}
// ideme vytvorit par zmien
for (int j = 0; j < v.size(); j++) for (int k = 0; k < di; k++)
{
int mask = (cnt - 1) ^ (3 << (2 * k)), nw = num[c[mask & v[j]]];
if (nw != -1) upd(dp[i][j], dp[i][nw] + 1);
}
// ideme na dalsi prvok
for (int j = 0; j < v.size(); j++)
{
int val = a[i];
for (int k = 0; k < di; k++)
{
int d = (v[j] >> (2 * k)) & 3;
if (d == 1) val = !val;
if (d == 2) val = 0;
if (d == 3) val = 1;
}
if (val == b[i]) upd(dp[i + 1][j], dp[i][j]);
}
}
int ans = inf;
for (int i = 0; i < v.size(); i++) upd(ans, dp[n][i]);
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
lamp.cpp: In function 'int main()':
lamp.cpp:46:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int j = 0; j < v.size(); j++) for (int k = 0; k < di; k++)
| ~~^~~~~~~~~~
lamp.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int j = 0; j < v.size(); j++)
| ~~^~~~~~~~~~
lamp.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0; i < v.size(); i++) upd(ans, dp[n][i]);
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |