# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
252997 |
2020-07-26T15:22:29 Z |
hollwo_pelw |
Lamps (JOI19_lamps) |
C++17 |
|
79 ms |
67144 KB |
/*
/+==================================================+\
//+--------------------------------------------------+\\
|.|\\...>>>>>>> Hollwo_Pelw(ass) 's code <<<<<<<...//|.|
\\+--------------------------------------------------+//
\+==================================================+/
*/
#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r) for (int i = l; i < r; i++)
//#define ForE(i, l, r) for (int i = l; i <= r; i++)
//#define Ford(i, r, l) for (int i = r; i > l; i--)
//#define FordE(i, r, l) for (int i = r; i >= l; i--)
//#define Fora(i, a) for (auto i : a)
// I/O
#define open(file, in, out) if (fopen(file in, "r")) { \
freopen(file in, "r", stdin); \
freopen(file out, "w", stdout); \
}
#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define setpre(n) fixed << setprecision(n)
// pair
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
// vector & !!?(string)
#define eb emplace_back
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define len(a) a.length()
// geometry calculate
#define pi acos(-1.0)
#define g_sin(a) sin(a*pi/180)
#define g_cos(a) cos(a*pi/180)
#define g_tan(a) tan(a*pi/180)
// set val
#define ms0(a) memset(a, 0, sizeof(a));
#define ms1(a) memset(a, 1, sizeof(a));
#define msn1(a) memset(a, -1, sizeof(a));
#define msinf(a) memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 100005, MAXM = 200010;
// code
#define int long long
int dp[(int) 1e6 + 6][8];
int tr[8][8];
void Solve() {
string a, b; int n;
cin >> n >> a >> b;
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
int t = (i | j) ^ i;
while (t){
tr[i][j] += t % 2;
t /= 2;
}
}
}
for (int i = 0; i <= n; i++){
for (int j = 0; j < 8; j++){
dp[i][j] = 1e9;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++){
if (a[i-1] == '1' & b[i-1] == '1'){
for (int j = 0; j < 8; j++){
dp[i][0] = min(dp[i][0], dp[i-1][j] + tr[j][0]);
dp[i][2] = min(dp[i][2], dp[i-1][j] + tr[j][2]);
dp[i][5] = min(dp[i][5], dp[i-1][j] + tr[j][5]);
}
}if (a[i-1] == '1' & b[i-1] == '0'){
for (int j = 0; j < 8; j++){
dp[i][1] = min(dp[i][1], dp[i-1][j] + tr[j][1]);
dp[i][4] = min(dp[i][4], dp[i-1][j] + tr[j][4]);
dp[i][6] = min(dp[i][6], dp[i-1][j] + tr[j][6]);
}
}if (a[i-1] == '0' & b[i-1] == '0'){
for (int j = 0; j < 8; j++){
dp[i][0] = min(dp[i][0], dp[i-1][j] + tr[j][0]);
dp[i][1] = min(dp[i][1], dp[i-1][j] + tr[j][1]);
dp[i][6] = min(dp[i][6], dp[i-1][j] + tr[j][6]);
}
}if (a[i-1] == '0' & b[i-1] == '1'){
for (int j = 0; j < 8; j++){
dp[i][2] = min(dp[i][2], dp[i-1][j] + tr[j][2]);
dp[i][4] = min(dp[i][4], dp[i-1][j] + tr[j][4]);
dp[i][5] = min(dp[i][5], dp[i-1][j] + tr[j][5]);
}
}
}
int ans = 1e9;
for (int i = 0; i < 8; i++){
ans = min(ans, dp[n][i]);
}
// for (int j = 0; j < 8; j ++){
// for (int i = 1; i <= n; i++){
// if (dp[i][j] == 1e9) cout << "X ";
// else cout << dp[i][j] << ' ';
// }
// cout << endl;
// }
cout << ans;
}
signed main(){
open("", ".inp", ".out");
FAST_IO; int TC = 1;
// cin >> TC;
while(TC--) Solve();
return 0;
}
/*
./-=====>>><<<-------- DEBUG -------->>><<<=====-\.
/.................................................\
+====================== INP ======================+
+====================== OUT ======================+
\................................................./
.\-=====>>><<<--------= END =-------->>><<<=====-/.
*/
Compilation message
lamp.cpp: In function 'void Solve()':
lamp.cpp:77:20: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
if (a[i-1] == '1' & b[i-1] == '1'){
lamp.cpp:83:21: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
}if (a[i-1] == '1' & b[i-1] == '0'){
lamp.cpp:89:21: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
}if (a[i-1] == '0' & b[i-1] == '0'){
lamp.cpp:95:21: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
}if (a[i-1] == '0' & b[i-1] == '1'){
lamp.cpp: In function 'int main()':
lamp.cpp:21:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(file in, "r", stdin); \
~~~~~~~^~~~~~~~~~~~~~~~~~~~~
lamp.cpp:118:5: note: in expansion of macro 'open'
open("", ".inp", ".out");
^~~~
lamp.cpp:22:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(file out, "w", stdout); \
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:118:5: note: in expansion of macro 'open'
open("", ".inp", ".out");
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
512 KB |
Output is correct |
41 |
Correct |
1 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
1 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
512 KB |
Output is correct |
54 |
Correct |
1 ms |
512 KB |
Output is correct |
55 |
Correct |
1 ms |
512 KB |
Output is correct |
56 |
Correct |
1 ms |
512 KB |
Output is correct |
57 |
Correct |
1 ms |
512 KB |
Output is correct |
58 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
56 ms |
67024 KB |
Output is correct |
8 |
Correct |
57 ms |
67040 KB |
Output is correct |
9 |
Correct |
56 ms |
67016 KB |
Output is correct |
10 |
Correct |
60 ms |
67016 KB |
Output is correct |
11 |
Correct |
54 ms |
67012 KB |
Output is correct |
12 |
Correct |
61 ms |
67088 KB |
Output is correct |
13 |
Correct |
60 ms |
67028 KB |
Output is correct |
14 |
Correct |
54 ms |
67020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
512 KB |
Output is correct |
41 |
Correct |
1 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
1 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
512 KB |
Output is correct |
54 |
Correct |
1 ms |
512 KB |
Output is correct |
55 |
Correct |
1 ms |
512 KB |
Output is correct |
56 |
Correct |
1 ms |
512 KB |
Output is correct |
57 |
Correct |
1 ms |
512 KB |
Output is correct |
58 |
Correct |
1 ms |
512 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
1 ms |
384 KB |
Output is correct |
62 |
Correct |
0 ms |
384 KB |
Output is correct |
63 |
Correct |
0 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
56 ms |
67024 KB |
Output is correct |
66 |
Correct |
57 ms |
67040 KB |
Output is correct |
67 |
Correct |
56 ms |
67016 KB |
Output is correct |
68 |
Correct |
60 ms |
67016 KB |
Output is correct |
69 |
Correct |
54 ms |
67012 KB |
Output is correct |
70 |
Correct |
61 ms |
67088 KB |
Output is correct |
71 |
Correct |
60 ms |
67028 KB |
Output is correct |
72 |
Correct |
54 ms |
67020 KB |
Output is correct |
73 |
Correct |
55 ms |
67052 KB |
Output is correct |
74 |
Correct |
58 ms |
67068 KB |
Output is correct |
75 |
Correct |
61 ms |
67012 KB |
Output is correct |
76 |
Correct |
55 ms |
67020 KB |
Output is correct |
77 |
Correct |
60 ms |
67020 KB |
Output is correct |
78 |
Correct |
55 ms |
67028 KB |
Output is correct |
79 |
Correct |
61 ms |
67020 KB |
Output is correct |
80 |
Correct |
55 ms |
67016 KB |
Output is correct |
81 |
Correct |
55 ms |
67004 KB |
Output is correct |
82 |
Correct |
55 ms |
67020 KB |
Output is correct |
83 |
Correct |
59 ms |
67016 KB |
Output is correct |
84 |
Correct |
59 ms |
67012 KB |
Output is correct |
85 |
Correct |
59 ms |
67016 KB |
Output is correct |
86 |
Correct |
62 ms |
67020 KB |
Output is correct |
87 |
Correct |
58 ms |
67016 KB |
Output is correct |
88 |
Correct |
59 ms |
67028 KB |
Output is correct |
89 |
Correct |
60 ms |
67144 KB |
Output is correct |
90 |
Correct |
59 ms |
67028 KB |
Output is correct |
91 |
Correct |
61 ms |
67080 KB |
Output is correct |
92 |
Correct |
69 ms |
67016 KB |
Output is correct |
93 |
Correct |
63 ms |
67016 KB |
Output is correct |
94 |
Correct |
63 ms |
67020 KB |
Output is correct |
95 |
Correct |
63 ms |
67012 KB |
Output is correct |
96 |
Correct |
79 ms |
67020 KB |
Output is correct |
97 |
Correct |
62 ms |
67032 KB |
Output is correct |
98 |
Correct |
63 ms |
67016 KB |
Output is correct |
99 |
Correct |
63 ms |
67016 KB |
Output is correct |
100 |
Correct |
64 ms |
67028 KB |
Output is correct |
101 |
Correct |
64 ms |
67056 KB |
Output is correct |
102 |
Correct |
64 ms |
66972 KB |
Output is correct |