# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
624069 | Loki_Nguyen | Lamps (JOI19_lamps) | C++14 | 74 ms | 16176 KiB |
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 <bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "tesddt"
#define pii pair<ll, pll>
using namespace std;
using ll = long long;
const int N = 1e6 + 2;
const ll mod = 998244353;
const ll base = 350;
const ll inf = 1e15;
int m, n, t, k, a[N], ans, dp[N][3];
void add(int& x, int y)
{
if(x == -1 || x > y)x = y;
}
void sol()
{
string A, B;
cin >> n >> A >> B;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
ans = -1;
for(int i = 0; i < n; i ++)
{
for(int l = 0; l < 3; l ++)
{
if(dp[i][l] == -1)continue;
//cout << i <<" "<<l<<" "<<dp[i][l] << '\n';
for(int r = 0; r < 3; r ++)
{
int cost = 0;
if(l != r && r > 0)++cost;
int vl, vr;
if(r > 0)vr = r-1;
else vr = A[i]-'0';
if(vr != B[i]-'0')
{
if(!i)++cost;
else
{
if(l > 0)vl = l-1;
else vl = A[i-1]-'0';
if(vl == B[i-1]-'0')++cost;
}
}
//cout << r <<" "<<cost << '\n';
add(dp[i+1][r], dp[i][l]+cost);
}
}
}
for(int i = 0; i < 3; i ++)if(dp[n][i] != -1)add(ans, dp[n][i]);
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(task ".inp", "r"))
{
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
int ntest = 1;
// cin >> ntest;
while (ntest-- > 0)
sol();
}
Compilation message (stderr)
# | 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... |