#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int mem[N][16];
int cost[16][16];
int eff[16][2];
int n;
string a,b;
vector< vector<int> > conv = {{}, {0}, {1}, {2}, {0,1} , {1,0}, {0,2}, {2,0}, {1,2}, {2,1} , {0,1,2}, {0,2,1}, {1,0,2}, {1,2,0}, {2,0,1}, {2,1,0}};
int get(int mas,int b)
{
vector<int> v=conv[mas];
for(int i:v)
{
if(i==0) b=0;
else if(i==1) b=1;
else b=1-b;
}
return b;
}
int calc(int a,int b)
{
vector<int> x=conv[a],y=conv[b];
int j=0;
for(int i=0;i<x.size()&&j<y.size();i++)
{
if(x[i]==y[j]) j++;
}
return y.size()-j;
}
int go(int ind,int mas)
{
//cout << ind << " " << mas << endl;
if(ind>=n) return 0;
if(mem[ind][mas]!=-1) return mem[ind][mas];
mem[ind][mas]=(1<<30);
for(int i=0;i<16;i++)
{
if(eff[i][a[ind]-'0']==b[ind]-'0')
{
mem[ind][mas]=min(mem[ind][mas],cost[mas][i]+go(ind+1,i));
}
}
return mem[ind][mas];
}
int main()
{
cin >> n >> a >> b;
memset(mem,-1,sizeof mem);
for(int i=0;i<16;i++)
{
for(int j=0;j<16;j++)
{
cost[i][j]=calc(i,j);
}
}
//cout << "OK" << endl;
for(int i=0;i<16;i++)
{
for(int k=0;k<2;k++)
eff[i][k]=get(i,k);
}
//cout << "OK" << endl;
cout << go(0,0) << endl;
}
Compilation message
lamp.cpp: In function 'int calc(int, int)':
lamp.cpp:31:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<x.size()&&j<y.size();i++)
~^~~~~~~~~
lamp.cpp:31:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<x.size()&&j<y.size();i++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
62968 KB |
Output is correct |
2 |
Correct |
54 ms |
62968 KB |
Output is correct |
3 |
Correct |
54 ms |
62968 KB |
Output is correct |
4 |
Correct |
54 ms |
62968 KB |
Output is correct |
5 |
Correct |
59 ms |
62968 KB |
Output is correct |
6 |
Correct |
54 ms |
62968 KB |
Output is correct |
7 |
Correct |
54 ms |
62968 KB |
Output is correct |
8 |
Correct |
54 ms |
62972 KB |
Output is correct |
9 |
Correct |
54 ms |
62968 KB |
Output is correct |
10 |
Correct |
54 ms |
62968 KB |
Output is correct |
11 |
Correct |
54 ms |
62888 KB |
Output is correct |
12 |
Correct |
54 ms |
62968 KB |
Output is correct |
13 |
Correct |
54 ms |
62968 KB |
Output is correct |
14 |
Correct |
54 ms |
62968 KB |
Output is correct |
15 |
Correct |
54 ms |
62968 KB |
Output is correct |
16 |
Correct |
54 ms |
62968 KB |
Output is correct |
17 |
Correct |
54 ms |
62968 KB |
Output is correct |
18 |
Correct |
55 ms |
62968 KB |
Output is correct |
19 |
Correct |
54 ms |
62968 KB |
Output is correct |
20 |
Correct |
54 ms |
62968 KB |
Output is correct |
21 |
Correct |
54 ms |
62968 KB |
Output is correct |
22 |
Correct |
55 ms |
62968 KB |
Output is correct |
23 |
Correct |
54 ms |
62968 KB |
Output is correct |
24 |
Correct |
54 ms |
62968 KB |
Output is correct |
25 |
Correct |
54 ms |
62968 KB |
Output is correct |
26 |
Correct |
54 ms |
62968 KB |
Output is correct |
27 |
Correct |
54 ms |
63096 KB |
Output is correct |
28 |
Correct |
54 ms |
62940 KB |
Output is correct |
29 |
Correct |
54 ms |
62968 KB |
Output is correct |
30 |
Correct |
63 ms |
62968 KB |
Output is correct |
31 |
Correct |
55 ms |
62968 KB |
Output is correct |
32 |
Correct |
60 ms |
62968 KB |
Output is correct |
33 |
Correct |
54 ms |
62968 KB |
Output is correct |
34 |
Correct |
54 ms |
62968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
62968 KB |
Output is correct |
2 |
Correct |
54 ms |
62968 KB |
Output is correct |
3 |
Correct |
54 ms |
62968 KB |
Output is correct |
4 |
Correct |
54 ms |
62968 KB |
Output is correct |
5 |
Correct |
59 ms |
62968 KB |
Output is correct |
6 |
Correct |
54 ms |
62968 KB |
Output is correct |
7 |
Correct |
54 ms |
62968 KB |
Output is correct |
8 |
Correct |
54 ms |
62972 KB |
Output is correct |
9 |
Correct |
54 ms |
62968 KB |
Output is correct |
10 |
Correct |
54 ms |
62968 KB |
Output is correct |
11 |
Correct |
54 ms |
62888 KB |
Output is correct |
12 |
Correct |
54 ms |
62968 KB |
Output is correct |
13 |
Correct |
54 ms |
62968 KB |
Output is correct |
14 |
Correct |
54 ms |
62968 KB |
Output is correct |
15 |
Correct |
54 ms |
62968 KB |
Output is correct |
16 |
Correct |
54 ms |
62968 KB |
Output is correct |
17 |
Correct |
54 ms |
62968 KB |
Output is correct |
18 |
Correct |
55 ms |
62968 KB |
Output is correct |
19 |
Correct |
54 ms |
62968 KB |
Output is correct |
20 |
Correct |
54 ms |
62968 KB |
Output is correct |
21 |
Correct |
54 ms |
62968 KB |
Output is correct |
22 |
Correct |
55 ms |
62968 KB |
Output is correct |
23 |
Correct |
54 ms |
62968 KB |
Output is correct |
24 |
Correct |
54 ms |
62968 KB |
Output is correct |
25 |
Correct |
54 ms |
62968 KB |
Output is correct |
26 |
Correct |
54 ms |
62968 KB |
Output is correct |
27 |
Correct |
54 ms |
63096 KB |
Output is correct |
28 |
Correct |
54 ms |
62940 KB |
Output is correct |
29 |
Correct |
54 ms |
62968 KB |
Output is correct |
30 |
Correct |
63 ms |
62968 KB |
Output is correct |
31 |
Correct |
55 ms |
62968 KB |
Output is correct |
32 |
Correct |
60 ms |
62968 KB |
Output is correct |
33 |
Correct |
54 ms |
62968 KB |
Output is correct |
34 |
Correct |
54 ms |
62968 KB |
Output is correct |
35 |
Correct |
55 ms |
63096 KB |
Output is correct |
36 |
Correct |
55 ms |
63096 KB |
Output is correct |
37 |
Correct |
55 ms |
63096 KB |
Output is correct |
38 |
Correct |
55 ms |
63096 KB |
Output is correct |
39 |
Correct |
55 ms |
63096 KB |
Output is correct |
40 |
Incorrect |
55 ms |
63096 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
62968 KB |
Output is correct |
2 |
Correct |
55 ms |
62940 KB |
Output is correct |
3 |
Correct |
54 ms |
63068 KB |
Output is correct |
4 |
Correct |
54 ms |
62968 KB |
Output is correct |
5 |
Correct |
54 ms |
62968 KB |
Output is correct |
6 |
Correct |
54 ms |
62968 KB |
Output is correct |
7 |
Correct |
651 ms |
143464 KB |
Output is correct |
8 |
Correct |
679 ms |
143464 KB |
Output is correct |
9 |
Correct |
659 ms |
143336 KB |
Output is correct |
10 |
Correct |
658 ms |
143588 KB |
Output is correct |
11 |
Correct |
659 ms |
143460 KB |
Output is correct |
12 |
Correct |
691 ms |
143416 KB |
Output is correct |
13 |
Correct |
676 ms |
143272 KB |
Output is correct |
14 |
Correct |
663 ms |
143464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
62968 KB |
Output is correct |
2 |
Correct |
54 ms |
62968 KB |
Output is correct |
3 |
Correct |
54 ms |
62968 KB |
Output is correct |
4 |
Correct |
54 ms |
62968 KB |
Output is correct |
5 |
Correct |
59 ms |
62968 KB |
Output is correct |
6 |
Correct |
54 ms |
62968 KB |
Output is correct |
7 |
Correct |
54 ms |
62968 KB |
Output is correct |
8 |
Correct |
54 ms |
62972 KB |
Output is correct |
9 |
Correct |
54 ms |
62968 KB |
Output is correct |
10 |
Correct |
54 ms |
62968 KB |
Output is correct |
11 |
Correct |
54 ms |
62888 KB |
Output is correct |
12 |
Correct |
54 ms |
62968 KB |
Output is correct |
13 |
Correct |
54 ms |
62968 KB |
Output is correct |
14 |
Correct |
54 ms |
62968 KB |
Output is correct |
15 |
Correct |
54 ms |
62968 KB |
Output is correct |
16 |
Correct |
54 ms |
62968 KB |
Output is correct |
17 |
Correct |
54 ms |
62968 KB |
Output is correct |
18 |
Correct |
55 ms |
62968 KB |
Output is correct |
19 |
Correct |
54 ms |
62968 KB |
Output is correct |
20 |
Correct |
54 ms |
62968 KB |
Output is correct |
21 |
Correct |
54 ms |
62968 KB |
Output is correct |
22 |
Correct |
55 ms |
62968 KB |
Output is correct |
23 |
Correct |
54 ms |
62968 KB |
Output is correct |
24 |
Correct |
54 ms |
62968 KB |
Output is correct |
25 |
Correct |
54 ms |
62968 KB |
Output is correct |
26 |
Correct |
54 ms |
62968 KB |
Output is correct |
27 |
Correct |
54 ms |
63096 KB |
Output is correct |
28 |
Correct |
54 ms |
62940 KB |
Output is correct |
29 |
Correct |
54 ms |
62968 KB |
Output is correct |
30 |
Correct |
63 ms |
62968 KB |
Output is correct |
31 |
Correct |
55 ms |
62968 KB |
Output is correct |
32 |
Correct |
60 ms |
62968 KB |
Output is correct |
33 |
Correct |
54 ms |
62968 KB |
Output is correct |
34 |
Correct |
54 ms |
62968 KB |
Output is correct |
35 |
Correct |
55 ms |
63096 KB |
Output is correct |
36 |
Correct |
55 ms |
63096 KB |
Output is correct |
37 |
Correct |
55 ms |
63096 KB |
Output is correct |
38 |
Correct |
55 ms |
63096 KB |
Output is correct |
39 |
Correct |
55 ms |
63096 KB |
Output is correct |
40 |
Incorrect |
55 ms |
63096 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |