이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define chmin(x, v) x = min(x, v)
using namespace std;
const int TAILLE_CHAINE = 1e6 + 1;
int dp[TAILLE_CHAINE][3][2];
int lenChaine;
bool depart[TAILLE_CHAINE], arrivee[TAILLE_CHAINE];
string d, a;
void litEntree();
void solve();
int main()
{
litEntree();
solve();
return 0;
}
void litEntree()
{
cin >> lenChaine;
cin.ignore();
getline(cin, d);
for (int idCara = 0; idCara < lenChaine; ++idCara){
depart[idCara] = d[idCara] - '0';
// cout << depart[idCara];
}
//cin.ignore();
getline(cin, a);
for (int idCara = 0; idCara < lenChaine; ++idCara)
arrivee[idCara] = a[idCara] - '0';
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 2; ++k)
if (j || k)
dp[0][j][k] = 1e6 + 5;
}
void solve()
{
for (int idCara = 1; idCara <= lenChaine; ++idCara)
{
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 2; ++k)
{
dp[idCara][j][k] = 1e6 + 5;
if (j == 0 && k != (arrivee[idCara - 1]^depart[idCara - 1]))
continue;
if (j == 1 && k != arrivee[idCara - 1])continue;
if (j == 2 && k == arrivee[idCara - 1])continue;
for (int newJ = 0; newJ < 3; ++ newJ)
{
chmin(dp[idCara][j][k], dp[idCara - 1][newJ][0] + (newJ != j && j > 0) +k);
chmin(dp[idCara][j][k], dp[idCara - 1][newJ][1] + (newJ != j && j > 0));
}
}
/*cout << "-------\n";
for (int i = 0; i < 3; ++i){
for (int j = 0; j < 2; ++j)
cout << dp[idCara][i][j] << " ";
cout << endl;
}
cout << "---\n";*/
}
int mini = 1e6 + 10;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 2; ++j)
chmin(mini, dp[lenChaine][i][j]);
cout << mini << endl;
}
# | 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... |