# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114300 | 2019-05-31T18:37:41 Z | tincamatei | Lamps (JOI19_lamps) | C++14 | 144 ms | 27896 KB |
#include <bits/stdc++.h> using namespace std; char getChar(FILE *fin) { char ch = fgetc(fin); while(!isdigit(ch)) ch = fgetc(fin); return ch; } const int MAX_N = 1000000; char str1[1+MAX_N]; char str2[1+MAX_N]; int dp[1+MAX_N][3][2]; // dp[N][0/1/2][0/1] = numarul minim de operatii daca la sfarsit n-am/am set 0/am set 1 si daca n-am/am operatie de xor int main() { int N, rez = MAX_N; scanf("%d", &N); for(int i = 1; i <= N; ++i) str1[i] = getChar(stdin); for(int i = 1; i <= N; ++i) str2[i] = getChar(stdin); for(int i = 0; i <= N; ++i) for(int setmask = 0; setmask < 3; ++setmask) for(int xormask = 0; xormask < 2; ++xormask) dp[i][setmask][xormask] = MAX_N + 1; dp[0][0][0] = 0; for(int i = 1; i <= N; ++i) { for(int setmask1 = 0; setmask1 < 3; ++setmask1) for(int xormask1 = 0; xormask1 < 2; ++xormask1) for(int setmask2 = 0; setmask2 < 3; ++setmask2) for(int xormask2 = 0; xormask2 < 2; ++xormask2) { char chVal = str1[i]; int cost = 0; if(setmask2 == 1) chVal = '0'; else if(setmask2 == 2) chVal = '1'; if(xormask2 == 1) chVal = '0' + '1' - chVal; if(setmask1 != setmask2 && setmask2 != 0) ++cost; if(xormask1 != xormask2 && xormask2 != 0) ++cost; if(chVal == str2[i]) dp[i][setmask2][xormask2] = min(dp[i - 1][setmask1][xormask1] + cost, dp[i][setmask2][xormask2]); } } for(int setmask = 0; setmask < 3; ++setmask) for(int xormask = 0; xormask < 2; ++xormask) rez = min(rez, dp[N][setmask][xormask]); printf("%d", rez); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 0 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 0 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 2 ms | 384 KB | Output is correct |
35 | Correct | 2 ms | 384 KB | Output is correct |
36 | Correct | 2 ms | 384 KB | Output is correct |
37 | Correct | 3 ms | 384 KB | Output is correct |
38 | Correct | 2 ms | 384 KB | Output is correct |
39 | Correct | 2 ms | 384 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 2 ms | 384 KB | Output is correct |
42 | Correct | 2 ms | 384 KB | Output is correct |
43 | Correct | 2 ms | 384 KB | Output is correct |
44 | Correct | 2 ms | 384 KB | Output is correct |
45 | Correct | 2 ms | 384 KB | Output is correct |
46 | Correct | 2 ms | 384 KB | Output is correct |
47 | Correct | 2 ms | 384 KB | Output is correct |
48 | Correct | 2 ms | 384 KB | Output is correct |
49 | Correct | 2 ms | 384 KB | Output is correct |
50 | Correct | 3 ms | 384 KB | Output is correct |
51 | Correct | 2 ms | 384 KB | Output is correct |
52 | Correct | 2 ms | 384 KB | Output is correct |
53 | Correct | 2 ms | 384 KB | Output is correct |
54 | Correct | 2 ms | 384 KB | Output is correct |
55 | Correct | 2 ms | 384 KB | Output is correct |
56 | Correct | 2 ms | 460 KB | Output is correct |
57 | Correct | 2 ms | 384 KB | Output is correct |
58 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 144 ms | 27768 KB | Output is correct |
8 | Correct | 111 ms | 27768 KB | Output is correct |
9 | Correct | 113 ms | 27844 KB | Output is correct |
10 | Correct | 113 ms | 27740 KB | Output is correct |
11 | Correct | 109 ms | 27768 KB | Output is correct |
12 | Correct | 101 ms | 27752 KB | Output is correct |
13 | Correct | 109 ms | 27768 KB | Output is correct |
14 | Correct | 108 ms | 27768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 0 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 2 ms | 384 KB | Output is correct |
35 | Correct | 2 ms | 384 KB | Output is correct |
36 | Correct | 2 ms | 384 KB | Output is correct |
37 | Correct | 3 ms | 384 KB | Output is correct |
38 | Correct | 2 ms | 384 KB | Output is correct |
39 | Correct | 2 ms | 384 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 2 ms | 384 KB | Output is correct |
42 | Correct | 2 ms | 384 KB | Output is correct |
43 | Correct | 2 ms | 384 KB | Output is correct |
44 | Correct | 2 ms | 384 KB | Output is correct |
45 | Correct | 2 ms | 384 KB | Output is correct |
46 | Correct | 2 ms | 384 KB | Output is correct |
47 | Correct | 2 ms | 384 KB | Output is correct |
48 | Correct | 2 ms | 384 KB | Output is correct |
49 | Correct | 2 ms | 384 KB | Output is correct |
50 | Correct | 3 ms | 384 KB | Output is correct |
51 | Correct | 2 ms | 384 KB | Output is correct |
52 | Correct | 2 ms | 384 KB | Output is correct |
53 | Correct | 2 ms | 384 KB | Output is correct |
54 | Correct | 2 ms | 384 KB | Output is correct |
55 | Correct | 2 ms | 384 KB | Output is correct |
56 | Correct | 2 ms | 460 KB | Output is correct |
57 | Correct | 2 ms | 384 KB | Output is correct |
58 | Correct | 2 ms | 384 KB | Output is correct |
59 | Correct | 1 ms | 384 KB | Output is correct |
60 | Correct | 2 ms | 384 KB | Output is correct |
61 | Correct | 2 ms | 384 KB | Output is correct |
62 | Correct | 2 ms | 384 KB | Output is correct |
63 | Correct | 2 ms | 384 KB | Output is correct |
64 | Correct | 2 ms | 384 KB | Output is correct |
65 | Correct | 144 ms | 27768 KB | Output is correct |
66 | Correct | 111 ms | 27768 KB | Output is correct |
67 | Correct | 113 ms | 27844 KB | Output is correct |
68 | Correct | 113 ms | 27740 KB | Output is correct |
69 | Correct | 109 ms | 27768 KB | Output is correct |
70 | Correct | 101 ms | 27752 KB | Output is correct |
71 | Correct | 109 ms | 27768 KB | Output is correct |
72 | Correct | 108 ms | 27768 KB | Output is correct |
73 | Correct | 120 ms | 27808 KB | Output is correct |
74 | Correct | 114 ms | 27768 KB | Output is correct |
75 | Correct | 100 ms | 27804 KB | Output is correct |
76 | Correct | 101 ms | 27768 KB | Output is correct |
77 | Correct | 114 ms | 27772 KB | Output is correct |
78 | Correct | 108 ms | 27768 KB | Output is correct |
79 | Correct | 136 ms | 27892 KB | Output is correct |
80 | Correct | 100 ms | 27768 KB | Output is correct |
81 | Correct | 108 ms | 27768 KB | Output is correct |
82 | Correct | 106 ms | 27768 KB | Output is correct |
83 | Correct | 108 ms | 27768 KB | Output is correct |
84 | Correct | 111 ms | 27896 KB | Output is correct |
85 | Correct | 107 ms | 27784 KB | Output is correct |
86 | Correct | 109 ms | 27768 KB | Output is correct |
87 | Correct | 112 ms | 27768 KB | Output is correct |
88 | Correct | 108 ms | 27764 KB | Output is correct |
89 | Correct | 108 ms | 27868 KB | Output is correct |
90 | Correct | 107 ms | 27768 KB | Output is correct |
91 | Correct | 117 ms | 27784 KB | Output is correct |
92 | Correct | 115 ms | 27768 KB | Output is correct |
93 | Correct | 113 ms | 27740 KB | Output is correct |
94 | Correct | 115 ms | 27744 KB | Output is correct |
95 | Correct | 115 ms | 27768 KB | Output is correct |
96 | Correct | 115 ms | 27768 KB | Output is correct |
97 | Correct | 112 ms | 27768 KB | Output is correct |
98 | Correct | 116 ms | 27772 KB | Output is correct |
99 | Correct | 115 ms | 27768 KB | Output is correct |
100 | Correct | 115 ms | 27776 KB | Output is correct |
101 | Correct | 127 ms | 27788 KB | Output is correct |
102 | Correct | 113 ms | 27768 KB | Output is correct |