Submission #1355803

#TimeUsernameProblemLanguageResultExecution timeMemory
1355803iamhereforfunLamps (JOI19_lamps)C++20
0 / 100
1 ms1092 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 2e5 + 5;
const int M = 2e6 + 5;
const long long K = (1LL << 60) - 1;
const int LG = 20;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 1e9 + 9;

int n, a[N], b[N], ans, l;
bool last = 0;

inline void solve()
{
    cin >> n;
    for (int x = 1; x <= n; x++)
    {
        char c;
        cin >> c;
        a[x] = c - '0';
    }
    for (int x = 1; x <= n; x++)
    {
        char c;
        cin >> c;
        b[x] = c - '0';
    }
    ans = 0;
    l = 1;
    while (l <= n)
    {
        int r = l;
        while (r <= n)
        {
            if (b[r] != b[l])
                break;
            r++;
        }
        r--;
        int cnt = 0;
        for (int x = l; x < r; x++)
        {
            if (a[x] != a[x + 1])
            {
                cnt++;
            }
        }
        if (!cnt)
        {
            if (b[l] == a[l])
            {
                last = 0;
            }
            else
            {
                if (!last)
                {
                    ans++;
                    last = 1;
                }
            }
        }
        else if (cnt == 1)
        {
            if (a[l] == b[l])
            {
                ans++;
                last = 1;
            }
            else
            {
                if (!last)
                    ans++;
                last = 0;
            }
        }
        else
        {
            ans++;
        }
        l = r + 1;
        // cout << ans << " " << r << "\n";
    }
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...