이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/*#define int int64_t
#define vi vector<int>
#define ii pair<int,int>
#define vb vector<bool>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define chkmax(a,b) a = max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()*/
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
int32_t main(){
ios_base::sync_with_stdio(false);
int n; cin>>n;
string a,b; cin>>a>>b;
for(char &c:a) c-='0';
for(char &c:b) c-='0';
vector<vector<int>> cost(6, vector<int>(6));
loop(x,0,6) loop(y,0,6){
if (y%2==1 && x%2!=1) cost[x][y]++; // start toggle
if (y%3==1 && x%3!=1) cost[x][y]++; // start zero
if (y%3==2 && x%3!=2) cost[x][y]++; // start one
}
vector<vector<int>> dp(n+1, vector<int>(6, INF));
loop(x,0,6) dp[0][x] = (x%2!=0) + (x%3!=0);
loop(i,0,n){
loop(x,0,6){
bool c = a[i];
if (x%3 == 1) c = 0; // set to zero
else if (x%3 == 2) c = 1; // set to one
if (x%2 == 1) c = !c; // toggle
if (c == b[i]){
loop(y,0,6){
dp[i+1][y] = min(dp[i+1][y], dp[i][x] + cost[x][y]);
}
}
}
}
cout<<dp[n][0]<<endl;
return 0;
}
/*
color a
cls
g++ lamps.cpp -o a & a
8
11011100
01101001
*/
# | 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... |