Submission #129189

# Submission time Handle Problem Language Result Execution time Memory
129189 2019-07-11T19:44:30 Z mahmoudbadawy Lamps (JOI19_lamps) C++17
100 / 100
719 ms 145544 KB
#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++;
	}*/
	int maxi=0;;
	for(int i=0;i<(1<<x.size());i++)
	{
		for(int j=0;j<(1<<y.size());j++)
		{
			vector<int> p1,p2;
			for(int k=0;k<max(x.size(),y.size());k++)
			{
				if(i&(1<<k)) p1.push_back(k);
				if(j&(1<<k)) p2.push_back(k);
			}
			int cur=0;
			for(int k=0;k<min(p1.size(),p2.size());k++)
				if(x[p1[k]]==y[p2[k]]) cur++;
			maxi=max(maxi,cur);
		}
	}
	return y.size()-maxi;
}

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:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int k=0;k<max(x.size(),y.size());k++)
                ~^~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int k=0;k<min(p1.size(),p2.size());k++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 53 ms 62968 KB Output is correct
2 Correct 53 ms 62968 KB Output is correct
3 Correct 53 ms 62940 KB Output is correct
4 Correct 53 ms 62968 KB Output is correct
5 Correct 53 ms 62908 KB Output is correct
6 Correct 53 ms 62988 KB Output is correct
7 Correct 53 ms 63096 KB Output is correct
8 Correct 54 ms 62968 KB Output is correct
9 Correct 53 ms 62968 KB Output is correct
10 Correct 54 ms 62968 KB Output is correct
11 Correct 53 ms 62884 KB Output is correct
12 Correct 53 ms 62968 KB Output is correct
13 Correct 53 ms 62968 KB Output is correct
14 Correct 53 ms 62968 KB Output is correct
15 Correct 53 ms 62968 KB Output is correct
16 Correct 53 ms 62968 KB Output is correct
17 Correct 53 ms 62944 KB Output is correct
18 Correct 53 ms 62968 KB Output is correct
19 Correct 53 ms 62968 KB Output is correct
20 Correct 53 ms 62968 KB Output is correct
21 Correct 53 ms 62968 KB Output is correct
22 Correct 66 ms 62968 KB Output is correct
23 Correct 60 ms 62968 KB Output is correct
24 Correct 57 ms 63056 KB Output is correct
25 Correct 53 ms 62968 KB Output is correct
26 Correct 53 ms 62968 KB Output is correct
27 Correct 53 ms 62968 KB Output is correct
28 Correct 53 ms 62968 KB Output is correct
29 Correct 53 ms 62872 KB Output is correct
30 Correct 56 ms 62968 KB Output is correct
31 Correct 53 ms 62968 KB Output is correct
32 Correct 53 ms 62900 KB Output is correct
33 Correct 53 ms 62972 KB Output is correct
34 Correct 54 ms 63016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 62968 KB Output is correct
2 Correct 53 ms 62968 KB Output is correct
3 Correct 53 ms 62940 KB Output is correct
4 Correct 53 ms 62968 KB Output is correct
5 Correct 53 ms 62908 KB Output is correct
6 Correct 53 ms 62988 KB Output is correct
7 Correct 53 ms 63096 KB Output is correct
8 Correct 54 ms 62968 KB Output is correct
9 Correct 53 ms 62968 KB Output is correct
10 Correct 54 ms 62968 KB Output is correct
11 Correct 53 ms 62884 KB Output is correct
12 Correct 53 ms 62968 KB Output is correct
13 Correct 53 ms 62968 KB Output is correct
14 Correct 53 ms 62968 KB Output is correct
15 Correct 53 ms 62968 KB Output is correct
16 Correct 53 ms 62968 KB Output is correct
17 Correct 53 ms 62944 KB Output is correct
18 Correct 53 ms 62968 KB Output is correct
19 Correct 53 ms 62968 KB Output is correct
20 Correct 53 ms 62968 KB Output is correct
21 Correct 53 ms 62968 KB Output is correct
22 Correct 66 ms 62968 KB Output is correct
23 Correct 60 ms 62968 KB Output is correct
24 Correct 57 ms 63056 KB Output is correct
25 Correct 53 ms 62968 KB Output is correct
26 Correct 53 ms 62968 KB Output is correct
27 Correct 53 ms 62968 KB Output is correct
28 Correct 53 ms 62968 KB Output is correct
29 Correct 53 ms 62872 KB Output is correct
30 Correct 56 ms 62968 KB Output is correct
31 Correct 53 ms 62968 KB Output is correct
32 Correct 53 ms 62900 KB Output is correct
33 Correct 53 ms 62972 KB Output is correct
34 Correct 54 ms 63016 KB Output is correct
35 Correct 55 ms 63112 KB Output is correct
36 Correct 55 ms 63112 KB Output is correct
37 Correct 55 ms 63124 KB Output is correct
38 Correct 55 ms 63096 KB Output is correct
39 Correct 54 ms 63136 KB Output is correct
40 Correct 64 ms 63140 KB Output is correct
41 Correct 63 ms 63100 KB Output is correct
42 Correct 55 ms 63096 KB Output is correct
43 Correct 54 ms 63096 KB Output is correct
44 Correct 54 ms 63096 KB Output is correct
45 Correct 54 ms 63068 KB Output is correct
46 Correct 55 ms 63096 KB Output is correct
47 Correct 58 ms 63068 KB Output is correct
48 Correct 55 ms 63096 KB Output is correct
49 Correct 55 ms 63096 KB Output is correct
50 Correct 55 ms 63096 KB Output is correct
51 Correct 57 ms 63068 KB Output is correct
52 Correct 55 ms 63096 KB Output is correct
53 Correct 54 ms 63184 KB Output is correct
54 Correct 55 ms 63096 KB Output is correct
55 Correct 62 ms 62968 KB Output is correct
56 Correct 55 ms 63096 KB Output is correct
57 Correct 55 ms 63068 KB Output is correct
58 Correct 64 ms 63088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 62968 KB Output is correct
2 Correct 53 ms 63060 KB Output is correct
3 Correct 58 ms 62912 KB Output is correct
4 Correct 53 ms 62968 KB Output is correct
5 Correct 53 ms 62968 KB Output is correct
6 Correct 55 ms 62880 KB Output is correct
7 Correct 667 ms 143256 KB Output is correct
8 Correct 654 ms 143344 KB Output is correct
9 Correct 674 ms 143364 KB Output is correct
10 Correct 654 ms 143476 KB Output is correct
11 Correct 655 ms 143332 KB Output is correct
12 Correct 658 ms 143468 KB Output is correct
13 Correct 662 ms 143412 KB Output is correct
14 Correct 652 ms 143460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 62968 KB Output is correct
2 Correct 53 ms 62968 KB Output is correct
3 Correct 53 ms 62940 KB Output is correct
4 Correct 53 ms 62968 KB Output is correct
5 Correct 53 ms 62908 KB Output is correct
6 Correct 53 ms 62988 KB Output is correct
7 Correct 53 ms 63096 KB Output is correct
8 Correct 54 ms 62968 KB Output is correct
9 Correct 53 ms 62968 KB Output is correct
10 Correct 54 ms 62968 KB Output is correct
11 Correct 53 ms 62884 KB Output is correct
12 Correct 53 ms 62968 KB Output is correct
13 Correct 53 ms 62968 KB Output is correct
14 Correct 53 ms 62968 KB Output is correct
15 Correct 53 ms 62968 KB Output is correct
16 Correct 53 ms 62968 KB Output is correct
17 Correct 53 ms 62944 KB Output is correct
18 Correct 53 ms 62968 KB Output is correct
19 Correct 53 ms 62968 KB Output is correct
20 Correct 53 ms 62968 KB Output is correct
21 Correct 53 ms 62968 KB Output is correct
22 Correct 66 ms 62968 KB Output is correct
23 Correct 60 ms 62968 KB Output is correct
24 Correct 57 ms 63056 KB Output is correct
25 Correct 53 ms 62968 KB Output is correct
26 Correct 53 ms 62968 KB Output is correct
27 Correct 53 ms 62968 KB Output is correct
28 Correct 53 ms 62968 KB Output is correct
29 Correct 53 ms 62872 KB Output is correct
30 Correct 56 ms 62968 KB Output is correct
31 Correct 53 ms 62968 KB Output is correct
32 Correct 53 ms 62900 KB Output is correct
33 Correct 53 ms 62972 KB Output is correct
34 Correct 54 ms 63016 KB Output is correct
35 Correct 55 ms 63112 KB Output is correct
36 Correct 55 ms 63112 KB Output is correct
37 Correct 55 ms 63124 KB Output is correct
38 Correct 55 ms 63096 KB Output is correct
39 Correct 54 ms 63136 KB Output is correct
40 Correct 64 ms 63140 KB Output is correct
41 Correct 63 ms 63100 KB Output is correct
42 Correct 55 ms 63096 KB Output is correct
43 Correct 54 ms 63096 KB Output is correct
44 Correct 54 ms 63096 KB Output is correct
45 Correct 54 ms 63068 KB Output is correct
46 Correct 55 ms 63096 KB Output is correct
47 Correct 58 ms 63068 KB Output is correct
48 Correct 55 ms 63096 KB Output is correct
49 Correct 55 ms 63096 KB Output is correct
50 Correct 55 ms 63096 KB Output is correct
51 Correct 57 ms 63068 KB Output is correct
52 Correct 55 ms 63096 KB Output is correct
53 Correct 54 ms 63184 KB Output is correct
54 Correct 55 ms 63096 KB Output is correct
55 Correct 62 ms 62968 KB Output is correct
56 Correct 55 ms 63096 KB Output is correct
57 Correct 55 ms 63068 KB Output is correct
58 Correct 64 ms 63088 KB Output is correct
59 Correct 53 ms 62968 KB Output is correct
60 Correct 53 ms 63060 KB Output is correct
61 Correct 58 ms 62912 KB Output is correct
62 Correct 53 ms 62968 KB Output is correct
63 Correct 53 ms 62968 KB Output is correct
64 Correct 55 ms 62880 KB Output is correct
65 Correct 667 ms 143256 KB Output is correct
66 Correct 654 ms 143344 KB Output is correct
67 Correct 674 ms 143364 KB Output is correct
68 Correct 654 ms 143476 KB Output is correct
69 Correct 655 ms 143332 KB Output is correct
70 Correct 658 ms 143468 KB Output is correct
71 Correct 662 ms 143412 KB Output is correct
72 Correct 652 ms 143460 KB Output is correct
73 Correct 648 ms 145468 KB Output is correct
74 Correct 652 ms 145360 KB Output is correct
75 Correct 660 ms 145372 KB Output is correct
76 Correct 657 ms 145344 KB Output is correct
77 Correct 647 ms 145328 KB Output is correct
78 Correct 649 ms 145384 KB Output is correct
79 Correct 655 ms 145488 KB Output is correct
80 Correct 707 ms 145252 KB Output is correct
81 Correct 657 ms 145440 KB Output is correct
82 Correct 646 ms 145436 KB Output is correct
83 Correct 692 ms 145392 KB Output is correct
84 Correct 681 ms 145400 KB Output is correct
85 Correct 681 ms 145400 KB Output is correct
86 Correct 679 ms 145380 KB Output is correct
87 Correct 683 ms 145280 KB Output is correct
88 Correct 677 ms 145388 KB Output is correct
89 Correct 681 ms 145544 KB Output is correct
90 Correct 680 ms 145252 KB Output is correct
91 Correct 691 ms 145364 KB Output is correct
92 Correct 698 ms 145400 KB Output is correct
93 Correct 706 ms 145316 KB Output is correct
94 Correct 702 ms 145380 KB Output is correct
95 Correct 699 ms 145324 KB Output is correct
96 Correct 699 ms 145252 KB Output is correct
97 Correct 706 ms 145316 KB Output is correct
98 Correct 699 ms 145376 KB Output is correct
99 Correct 701 ms 145320 KB Output is correct
100 Correct 719 ms 145452 KB Output is correct
101 Correct 699 ms 145380 KB Output is correct
102 Correct 704 ms 145252 KB Output is correct