# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
158549 |
2019-10-17T18:45:56 Z |
Mounir |
Lamps (JOI19_lamps) |
C++14 |
|
171 ms |
28212 KB |
#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 i = 0; i < lenChaine; ++i)
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 2; ++k)
dp[i][j][k] = 1e6 + 5;
}
void solve()
{
for (int idCara = 0; idCara < lenChaine; ++idCara)
{
if (idCara == 0)
{
if (depart[idCara] == arrivee[idCara])
dp[idCara][2][0] = 0;
else
dp[idCara][2][1] = 1;
dp[idCara][arrivee[idCara]][0] = dp[idCara][arrivee[idCara]][1] = 1;
dp[idCara][arrivee[idCara]][1]++;
}
else
{
chmin(dp[idCara][arrivee[idCara]][0], dp[idCara - 1][arrivee[idCara]][0]);
chmin(dp[idCara][arrivee[idCara]][0], dp[idCara - 1][arrivee[idCara]][1]);
chmin(dp[idCara][arrivee[idCara]][0], dp[idCara - 1][!arrivee[idCara]][0] + 1);
chmin(dp[idCara][arrivee[idCara]][0], dp[idCara - 1][!arrivee[idCara]][1] + 1);
chmin(dp[idCara][arrivee[idCara]][0], dp[idCara - 1][2][0] + 1);
chmin(dp[idCara][arrivee[idCara]][0], dp[idCara - 1][2][1] + 1);
chmin(dp[idCara][arrivee[idCara]][1], dp[idCara - 1][arrivee[idCara]][0] + 1);
chmin(dp[idCara][arrivee[idCara]][1], dp[idCara - 1][arrivee[idCara]][1]);
chmin(dp[idCara][arrivee[idCara]][1], dp[idCara - 1][!arrivee[idCara]][0] + 2);
chmin(dp[idCara][arrivee[idCara]][1], dp[idCara - 1][!arrivee[idCara]][1] + 1);
chmin(dp[idCara][arrivee[idCara]][1], dp[idCara - 1][2][0] + 2);
chmin(dp[idCara][arrivee[idCara]][1], dp[idCara - 1][2][1] + 1);
for (int idDelta = 0; idDelta < 3; ++idDelta)
for (int idChange = 0; idChange < 2; ++ idChange)
{
if (arrivee[idCara] == depart[idCara])
chmin(dp[idCara][2][0], dp[idCara - 1][idDelta][idChange]);
else
chmin(dp[idCara][2][1], dp[idCara - 1][idDelta][idChange] + 1 - idChange);
}
}
/*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 - 1][i][j]);
cout << mini << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
396 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
157 ms |
28128 KB |
Output is correct |
8 |
Correct |
171 ms |
28104 KB |
Output is correct |
9 |
Correct |
158 ms |
28028 KB |
Output is correct |
10 |
Correct |
157 ms |
27984 KB |
Output is correct |
11 |
Correct |
158 ms |
28132 KB |
Output is correct |
12 |
Correct |
159 ms |
28212 KB |
Output is correct |
13 |
Correct |
157 ms |
28176 KB |
Output is correct |
14 |
Correct |
158 ms |
28068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |