# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329729 | Rainbowbunny | Lamps (JOI19_lamps) | C++17 | 118 ms | 35888 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>
using namespace std;
int n;
string c, d;
int cost[6][6];
int a[1000005], b[1000005];
int dp[1000005][6];
int ans = 1e9;
int main()
{
for(int i = 0; i < 6; i++)
{
for(int j = 0; j < 6; j++)
{
if(i / 2 != j / 2 && j / 2 != 0)
{
++cost[i][j];
}
if(i % 2 != j % 2 && j % 2 != 0)
{
++cost[i][j];
}
}
}
cin >> n >> c >> d;
for(int i = 1; i <= n; i++)
{
a[i] = c[i - 1] - '0';
b[i] = d[i - 1] - '0';
}
for(int i = 1; i <= 5; i++)
{
dp[0][i] = 1e9;
}
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < 6; j++)
{
dp[i][j] = 1e9;
int cur = a[i];
if(j / 2 == 1)
{
cur = 0;
}
else if(j / 2 == 2)
{
cur = 1;
}
if(cur ^ (j & 1) == b[i])
{
for(int k = 0; k < 6; k++)
{
dp[i][j] = min(dp[i][j], dp[i - 1][k] + cost[k][j]);
}
}
}
}
for(int i = 0; i < 6; i++)
{
ans = min(ans, dp[n][i]);
}
cout << ans;
}
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... |