Submission #158553

# Submission time Handle Problem Language Result Execution time Memory
158553 2019-10-17T19:11:05 Z Mounir Lamps (JOI19_lamps) C++14
100 / 100
190 ms 29944 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 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
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 376 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 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 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 376 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 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 176 ms 29360 KB Output is correct
8 Correct 176 ms 29288 KB Output is correct
9 Correct 177 ms 29288 KB Output is correct
10 Correct 189 ms 29276 KB Output is correct
11 Correct 180 ms 29256 KB Output is correct
12 Correct 176 ms 29284 KB Output is correct
13 Correct 179 ms 29284 KB Output is correct
14 Correct 177 ms 29220 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 376 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 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 344 KB Output is correct
60 Correct 2 ms 376 KB Output is correct
61 Correct 2 ms 380 KB Output is correct
62 Correct 2 ms 380 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 176 ms 29360 KB Output is correct
66 Correct 176 ms 29288 KB Output is correct
67 Correct 177 ms 29288 KB Output is correct
68 Correct 189 ms 29276 KB Output is correct
69 Correct 180 ms 29256 KB Output is correct
70 Correct 176 ms 29284 KB Output is correct
71 Correct 179 ms 29284 KB Output is correct
72 Correct 177 ms 29220 KB Output is correct
73 Correct 178 ms 29836 KB Output is correct
74 Correct 176 ms 29796 KB Output is correct
75 Correct 176 ms 29800 KB Output is correct
76 Correct 176 ms 29848 KB Output is correct
77 Correct 176 ms 29852 KB Output is correct
78 Correct 175 ms 29800 KB Output is correct
79 Correct 176 ms 29828 KB Output is correct
80 Correct 176 ms 29836 KB Output is correct
81 Correct 176 ms 29796 KB Output is correct
82 Correct 176 ms 29884 KB Output is correct
83 Correct 181 ms 29792 KB Output is correct
84 Correct 182 ms 29896 KB Output is correct
85 Correct 184 ms 29788 KB Output is correct
86 Correct 182 ms 29824 KB Output is correct
87 Correct 183 ms 29872 KB Output is correct
88 Correct 182 ms 29944 KB Output is correct
89 Correct 182 ms 29892 KB Output is correct
90 Correct 186 ms 29844 KB Output is correct
91 Correct 184 ms 29788 KB Output is correct
92 Correct 186 ms 29856 KB Output is correct
93 Correct 187 ms 29864 KB Output is correct
94 Correct 187 ms 29824 KB Output is correct
95 Correct 186 ms 29800 KB Output is correct
96 Correct 187 ms 29768 KB Output is correct
97 Correct 187 ms 29796 KB Output is correct
98 Correct 186 ms 29796 KB Output is correct
99 Correct 187 ms 29924 KB Output is correct
100 Correct 190 ms 29800 KB Output is correct
101 Correct 190 ms 29812 KB Output is correct
102 Correct 186 ms 29804 KB Output is correct