# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
624412 |
2022-08-08T08:24:12 Z |
pooyashams |
Lamps (JOI19_lamps) |
C++14 |
|
46 ms |
51224 KB |
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define endl '\n'
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 1e6+10;
const int inf = 1e9;
int dp[maxn][2][3];
int mnt[maxn][2];
int mna[maxn][3];
int mno[maxn];
char s[maxn];
char t[maxn];
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
for(int i = 0; i < maxn; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 3; k++)
dp[i][j][k] = inf;
{
int i = 0;
dp[i][0][0] = 0;
mnt[i][0] = min(dp[i][0][0], min(dp[i][0][1], dp[i][0][2]));
mnt[i][1] = min(dp[i][1][0], min(dp[i][1][1], dp[i][1][2]));
mno[i] = min(mnt[i][0], mnt[i][1]);
for(int k = 0; k < 3; k++)
mna[i][k] = min(dp[i][0][k], dp[i][1][k]);
}
int n; cin >> n;
cin >> (s+1);
cin >> (t+1);
for(int i = 1; i <= n; i++)
{
if(s[i] == t[i])
{
dp[i][0][0] = mno[i-1];
dp[i][1][0] = inf;
}
else
{
dp[i][0][0] = inf;
dp[i][1][0] = min(mnt[i-1][1], mno[i-1]+1);
}
//
if(t[i] == '1')
{
dp[i][0][1] = inf;
dp[i][0][2] = min(mno[i-1]+1, mna[i-1][2]);
dp[i][1][1] = min( min(mnt[i-1][1]+1, mna[i-1][1]+1), min(dp[i-1][1][1], 2+mno[i-1]) );
dp[i][1][2] = inf;
}
else
{
dp[i][0][1] = min(mno[i-1]+1, mna[i-1][1]);
dp[i][0][2] = inf;
dp[i][1][1] = inf;
dp[i][1][2] = min( min(mnt[i-1][1]+1, mna[i-1][2]+1), min(dp[i-1][1][2], 2+mno[i-1]) );
}
//
mnt[i][0] = min(dp[i][0][0], min(dp[i][0][1], dp[i][0][2]));
mnt[i][1] = min(dp[i][1][0], min(dp[i][1][1], dp[i][1][2]));
mno[i] = min(mnt[i][0], mnt[i][1]);
for(int k = 0; k < 3; k++)
mna[i][k] = min(dp[i][0][k], dp[i][1][k]);
//cerr << dp[i][0][0] << " " << dp[i][0][1] << " " << dp[i][0][2] << endl;
//cerr << dp[i][1][0] << " " << dp[i][1][1] << " " << dp[i][1][2] << endl;
//cerr << "---- " << (s[i] == t[i]) << endl;
}
cout << mno[n] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23712 KB |
Output is correct |
4 |
Correct |
12 ms |
23832 KB |
Output is correct |
5 |
Correct |
11 ms |
23832 KB |
Output is correct |
6 |
Correct |
11 ms |
23832 KB |
Output is correct |
7 |
Correct |
13 ms |
23776 KB |
Output is correct |
8 |
Correct |
11 ms |
23828 KB |
Output is correct |
9 |
Correct |
11 ms |
23832 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23764 KB |
Output is correct |
12 |
Correct |
11 ms |
23764 KB |
Output is correct |
13 |
Correct |
11 ms |
23828 KB |
Output is correct |
14 |
Correct |
13 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23800 KB |
Output is correct |
16 |
Correct |
11 ms |
23764 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23828 KB |
Output is correct |
19 |
Correct |
11 ms |
23756 KB |
Output is correct |
20 |
Correct |
11 ms |
23832 KB |
Output is correct |
21 |
Correct |
12 ms |
23828 KB |
Output is correct |
22 |
Correct |
11 ms |
23828 KB |
Output is correct |
23 |
Correct |
12 ms |
23892 KB |
Output is correct |
24 |
Correct |
12 ms |
23744 KB |
Output is correct |
25 |
Correct |
13 ms |
23752 KB |
Output is correct |
26 |
Correct |
11 ms |
23836 KB |
Output is correct |
27 |
Correct |
12 ms |
23732 KB |
Output is correct |
28 |
Correct |
11 ms |
23764 KB |
Output is correct |
29 |
Correct |
12 ms |
23892 KB |
Output is correct |
30 |
Correct |
12 ms |
23840 KB |
Output is correct |
31 |
Correct |
11 ms |
23764 KB |
Output is correct |
32 |
Correct |
11 ms |
23764 KB |
Output is correct |
33 |
Correct |
12 ms |
23720 KB |
Output is correct |
34 |
Correct |
12 ms |
23792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23712 KB |
Output is correct |
4 |
Correct |
12 ms |
23832 KB |
Output is correct |
5 |
Correct |
11 ms |
23832 KB |
Output is correct |
6 |
Correct |
11 ms |
23832 KB |
Output is correct |
7 |
Correct |
13 ms |
23776 KB |
Output is correct |
8 |
Correct |
11 ms |
23828 KB |
Output is correct |
9 |
Correct |
11 ms |
23832 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23764 KB |
Output is correct |
12 |
Correct |
11 ms |
23764 KB |
Output is correct |
13 |
Correct |
11 ms |
23828 KB |
Output is correct |
14 |
Correct |
13 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23800 KB |
Output is correct |
16 |
Correct |
11 ms |
23764 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23828 KB |
Output is correct |
19 |
Correct |
11 ms |
23756 KB |
Output is correct |
20 |
Correct |
11 ms |
23832 KB |
Output is correct |
21 |
Correct |
12 ms |
23828 KB |
Output is correct |
22 |
Correct |
11 ms |
23828 KB |
Output is correct |
23 |
Correct |
12 ms |
23892 KB |
Output is correct |
24 |
Correct |
12 ms |
23744 KB |
Output is correct |
25 |
Correct |
13 ms |
23752 KB |
Output is correct |
26 |
Correct |
11 ms |
23836 KB |
Output is correct |
27 |
Correct |
12 ms |
23732 KB |
Output is correct |
28 |
Correct |
11 ms |
23764 KB |
Output is correct |
29 |
Correct |
12 ms |
23892 KB |
Output is correct |
30 |
Correct |
12 ms |
23840 KB |
Output is correct |
31 |
Correct |
11 ms |
23764 KB |
Output is correct |
32 |
Correct |
11 ms |
23764 KB |
Output is correct |
33 |
Correct |
12 ms |
23720 KB |
Output is correct |
34 |
Correct |
12 ms |
23792 KB |
Output is correct |
35 |
Correct |
13 ms |
23808 KB |
Output is correct |
36 |
Correct |
11 ms |
23776 KB |
Output is correct |
37 |
Correct |
11 ms |
23768 KB |
Output is correct |
38 |
Correct |
12 ms |
23764 KB |
Output is correct |
39 |
Correct |
11 ms |
23848 KB |
Output is correct |
40 |
Correct |
11 ms |
23764 KB |
Output is correct |
41 |
Correct |
11 ms |
23764 KB |
Output is correct |
42 |
Correct |
13 ms |
23764 KB |
Output is correct |
43 |
Correct |
12 ms |
23764 KB |
Output is correct |
44 |
Correct |
11 ms |
23864 KB |
Output is correct |
45 |
Correct |
12 ms |
23832 KB |
Output is correct |
46 |
Correct |
12 ms |
23764 KB |
Output is correct |
47 |
Correct |
11 ms |
23832 KB |
Output is correct |
48 |
Correct |
13 ms |
23828 KB |
Output is correct |
49 |
Correct |
11 ms |
23764 KB |
Output is correct |
50 |
Correct |
13 ms |
23832 KB |
Output is correct |
51 |
Correct |
13 ms |
23764 KB |
Output is correct |
52 |
Correct |
14 ms |
23820 KB |
Output is correct |
53 |
Correct |
14 ms |
23764 KB |
Output is correct |
54 |
Correct |
12 ms |
23832 KB |
Output is correct |
55 |
Correct |
11 ms |
23828 KB |
Output is correct |
56 |
Correct |
12 ms |
23764 KB |
Output is correct |
57 |
Correct |
11 ms |
23840 KB |
Output is correct |
58 |
Correct |
11 ms |
23776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23828 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23764 KB |
Output is correct |
4 |
Correct |
11 ms |
23796 KB |
Output is correct |
5 |
Correct |
12 ms |
23716 KB |
Output is correct |
6 |
Correct |
13 ms |
23772 KB |
Output is correct |
7 |
Correct |
33 ms |
51164 KB |
Output is correct |
8 |
Correct |
33 ms |
51164 KB |
Output is correct |
9 |
Correct |
34 ms |
51124 KB |
Output is correct |
10 |
Correct |
35 ms |
51164 KB |
Output is correct |
11 |
Correct |
33 ms |
51172 KB |
Output is correct |
12 |
Correct |
35 ms |
51088 KB |
Output is correct |
13 |
Correct |
36 ms |
51172 KB |
Output is correct |
14 |
Correct |
33 ms |
51164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23712 KB |
Output is correct |
4 |
Correct |
12 ms |
23832 KB |
Output is correct |
5 |
Correct |
11 ms |
23832 KB |
Output is correct |
6 |
Correct |
11 ms |
23832 KB |
Output is correct |
7 |
Correct |
13 ms |
23776 KB |
Output is correct |
8 |
Correct |
11 ms |
23828 KB |
Output is correct |
9 |
Correct |
11 ms |
23832 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23764 KB |
Output is correct |
12 |
Correct |
11 ms |
23764 KB |
Output is correct |
13 |
Correct |
11 ms |
23828 KB |
Output is correct |
14 |
Correct |
13 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23800 KB |
Output is correct |
16 |
Correct |
11 ms |
23764 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23828 KB |
Output is correct |
19 |
Correct |
11 ms |
23756 KB |
Output is correct |
20 |
Correct |
11 ms |
23832 KB |
Output is correct |
21 |
Correct |
12 ms |
23828 KB |
Output is correct |
22 |
Correct |
11 ms |
23828 KB |
Output is correct |
23 |
Correct |
12 ms |
23892 KB |
Output is correct |
24 |
Correct |
12 ms |
23744 KB |
Output is correct |
25 |
Correct |
13 ms |
23752 KB |
Output is correct |
26 |
Correct |
11 ms |
23836 KB |
Output is correct |
27 |
Correct |
12 ms |
23732 KB |
Output is correct |
28 |
Correct |
11 ms |
23764 KB |
Output is correct |
29 |
Correct |
12 ms |
23892 KB |
Output is correct |
30 |
Correct |
12 ms |
23840 KB |
Output is correct |
31 |
Correct |
11 ms |
23764 KB |
Output is correct |
32 |
Correct |
11 ms |
23764 KB |
Output is correct |
33 |
Correct |
12 ms |
23720 KB |
Output is correct |
34 |
Correct |
12 ms |
23792 KB |
Output is correct |
35 |
Correct |
13 ms |
23808 KB |
Output is correct |
36 |
Correct |
11 ms |
23776 KB |
Output is correct |
37 |
Correct |
11 ms |
23768 KB |
Output is correct |
38 |
Correct |
12 ms |
23764 KB |
Output is correct |
39 |
Correct |
11 ms |
23848 KB |
Output is correct |
40 |
Correct |
11 ms |
23764 KB |
Output is correct |
41 |
Correct |
11 ms |
23764 KB |
Output is correct |
42 |
Correct |
13 ms |
23764 KB |
Output is correct |
43 |
Correct |
12 ms |
23764 KB |
Output is correct |
44 |
Correct |
11 ms |
23864 KB |
Output is correct |
45 |
Correct |
12 ms |
23832 KB |
Output is correct |
46 |
Correct |
12 ms |
23764 KB |
Output is correct |
47 |
Correct |
11 ms |
23832 KB |
Output is correct |
48 |
Correct |
13 ms |
23828 KB |
Output is correct |
49 |
Correct |
11 ms |
23764 KB |
Output is correct |
50 |
Correct |
13 ms |
23832 KB |
Output is correct |
51 |
Correct |
13 ms |
23764 KB |
Output is correct |
52 |
Correct |
14 ms |
23820 KB |
Output is correct |
53 |
Correct |
14 ms |
23764 KB |
Output is correct |
54 |
Correct |
12 ms |
23832 KB |
Output is correct |
55 |
Correct |
11 ms |
23828 KB |
Output is correct |
56 |
Correct |
12 ms |
23764 KB |
Output is correct |
57 |
Correct |
11 ms |
23840 KB |
Output is correct |
58 |
Correct |
11 ms |
23776 KB |
Output is correct |
59 |
Correct |
12 ms |
23828 KB |
Output is correct |
60 |
Correct |
11 ms |
23764 KB |
Output is correct |
61 |
Correct |
11 ms |
23764 KB |
Output is correct |
62 |
Correct |
11 ms |
23796 KB |
Output is correct |
63 |
Correct |
12 ms |
23716 KB |
Output is correct |
64 |
Correct |
13 ms |
23772 KB |
Output is correct |
65 |
Correct |
33 ms |
51164 KB |
Output is correct |
66 |
Correct |
33 ms |
51164 KB |
Output is correct |
67 |
Correct |
34 ms |
51124 KB |
Output is correct |
68 |
Correct |
35 ms |
51164 KB |
Output is correct |
69 |
Correct |
33 ms |
51172 KB |
Output is correct |
70 |
Correct |
35 ms |
51088 KB |
Output is correct |
71 |
Correct |
36 ms |
51172 KB |
Output is correct |
72 |
Correct |
33 ms |
51164 KB |
Output is correct |
73 |
Correct |
33 ms |
51224 KB |
Output is correct |
74 |
Correct |
35 ms |
51172 KB |
Output is correct |
75 |
Correct |
35 ms |
51148 KB |
Output is correct |
76 |
Correct |
36 ms |
51176 KB |
Output is correct |
77 |
Correct |
40 ms |
51128 KB |
Output is correct |
78 |
Correct |
34 ms |
51064 KB |
Output is correct |
79 |
Correct |
33 ms |
51184 KB |
Output is correct |
80 |
Correct |
35 ms |
51088 KB |
Output is correct |
81 |
Correct |
39 ms |
51104 KB |
Output is correct |
82 |
Correct |
35 ms |
51168 KB |
Output is correct |
83 |
Correct |
36 ms |
51152 KB |
Output is correct |
84 |
Correct |
39 ms |
51172 KB |
Output is correct |
85 |
Correct |
36 ms |
51180 KB |
Output is correct |
86 |
Correct |
38 ms |
51084 KB |
Output is correct |
87 |
Correct |
37 ms |
51060 KB |
Output is correct |
88 |
Correct |
38 ms |
51164 KB |
Output is correct |
89 |
Correct |
38 ms |
51104 KB |
Output is correct |
90 |
Correct |
37 ms |
51168 KB |
Output is correct |
91 |
Correct |
38 ms |
51184 KB |
Output is correct |
92 |
Correct |
41 ms |
51080 KB |
Output is correct |
93 |
Correct |
39 ms |
51168 KB |
Output is correct |
94 |
Correct |
41 ms |
51088 KB |
Output is correct |
95 |
Correct |
46 ms |
51076 KB |
Output is correct |
96 |
Correct |
39 ms |
51172 KB |
Output is correct |
97 |
Correct |
41 ms |
51116 KB |
Output is correct |
98 |
Correct |
40 ms |
51104 KB |
Output is correct |
99 |
Correct |
40 ms |
51164 KB |
Output is correct |
100 |
Correct |
40 ms |
51176 KB |
Output is correct |
101 |
Correct |
40 ms |
51164 KB |
Output is correct |
102 |
Correct |
41 ms |
51148 KB |
Output is correct |