# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
106068 | Alexa2001 | Lamps (JOI19_lamps) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1e6 + 5;
static void min_to(int &x, int y) { if(x>y) x=y; }
int dp[Nmax][6], apply[2][6], go[6][6];
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false);
int n, i, j, k;
string A, B;
cin >> n;
cin >> A >> B;
for(auto &it : A) it -= '0';
for(auto &it : B) it -= '0';
for(i=0; i<6; ++i)
for(j=0; j<6; ++j)
go[i][j] = (i/3 == 1 && j/3 == 0) + (i%3 != 2 && j%3 != i%3);
for(i=0; i<2; ++i)
for(j=0; j<6; ++j)
apply[i][j] = (j%3 == 2 ? i : j%3) ^ (j/3);
for(i=0; i<=n; ++i)
for(j=0; j<6; ++j)
dp[i][j] = 1e9;
dp[0][2] = 0;
for(i=0; i<n; ++i)
for(k=0; k<6; ++k)
if(apply[A[i]][k] == B[i])
for(j=0; j<6; ++j)
min_to(dp[i+1][k], dp[i][j] + go[j][k]);
int ans = 1e9;
for(i=0; i<6; ++i) min_to(ans, dp[n][i] + go[i][2]);
cout << ans << '\n';
return 0;
}