답안 #132599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132599 2019-07-19T08:08:11 Z ekrem Lamps (JOI19_lamps) C++
100 / 100
292 ms 117884 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, c[10][10], dp[N][9];
char a[N], b[N];

char yap(char x, int ne){
	char xx = 1 - (x - '0') + '0';
	if(ne == 0 or ne == 3 or ne == 4)
		return '0';
	if(ne == 1 or ne == 2 or ne == 5)
		return '1';
	if(ne == 6)
		return xx;
	return x;
}

int f(int ind, int ne){
	int &r = dp[ind][ne];
	if(r != -1)
		return r;
	if(ind == n + 1)
		return 0;
	r = inf;
	for(int i = 0; i < 8; i++)
		if(yap(a[ind], i) == b[ind]){
			r = min(r, c[ne][i] + f(ind + 1, i));
			// cout << 
		}
	return r;

}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	memset(dp, -1, sizeof dp);
	scanf("%d %s %s",&n, a + 1, b + 1);
	c[7][7]=0;c[7][0]=1;c[7][1]=1;c[7][2]=2;c[7][3]=2;c[7][4]=2;c[7][5]=3;c[7][6]=1;
	c[6][0]=1;c[6][1]=1;c[6][2]=c[6][3]=c[6][4]=c[6][5]=1;c[6][6]=c[6][7]=0;
	c[5][0]=1;c[5][1]=0;c[5][2]=1;c[5][3]=1;c[5][4]=1;c[5][5]=0;c[5][6]=c[5][7]=0;
	c[4][0]=0;c[4][1]=1;c[4][2]=1;c[4][3]=1;c[4][4]=0;c[4][5]=1;c[4][6]=0;c[4][7]=0;
	c[3][0]=1;c[3][1]=0;c[3][2]=1;c[3][3]=0;c[3][4]=1;c[3][5]=1;c[3][6]=0;c[3][7]=0;
	c[2][0]=0;c[2][1]=1;c[2][2]=0;c[2][3]=1;c[2][4]=1;c[2][5]=1;c[2][6]=0;c[2][7]=0;
	c[1][0]=1;c[1][1]=0;c[1][2]=2;c[1][3]=1;c[1][4]=2;c[1][5]=1;c[1][6]=1;c[1][7]=0;
	c[0][0]=0;c[0][1]=1;c[0][2]=1;c[0][3]=2;c[0][4]=1;c[0][5]=2;c[0][6]=1;c[0][7]=0;
	printf("%d\n", f(1, 7));
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s %s",&n, a + 1, b + 1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 35576 KB Output is correct
2 Correct 31 ms 35576 KB Output is correct
3 Correct 41 ms 35532 KB Output is correct
4 Correct 35 ms 35576 KB Output is correct
5 Correct 31 ms 35484 KB Output is correct
6 Correct 38 ms 35576 KB Output is correct
7 Correct 31 ms 35576 KB Output is correct
8 Correct 30 ms 35576 KB Output is correct
9 Correct 31 ms 35576 KB Output is correct
10 Correct 31 ms 35652 KB Output is correct
11 Correct 31 ms 35576 KB Output is correct
12 Correct 31 ms 35596 KB Output is correct
13 Correct 31 ms 35704 KB Output is correct
14 Correct 31 ms 35576 KB Output is correct
15 Correct 30 ms 35576 KB Output is correct
16 Correct 30 ms 35580 KB Output is correct
17 Correct 31 ms 35704 KB Output is correct
18 Correct 31 ms 35576 KB Output is correct
19 Correct 31 ms 35576 KB Output is correct
20 Correct 31 ms 35576 KB Output is correct
21 Correct 31 ms 35576 KB Output is correct
22 Correct 31 ms 35576 KB Output is correct
23 Correct 31 ms 35576 KB Output is correct
24 Correct 38 ms 35576 KB Output is correct
25 Correct 32 ms 35576 KB Output is correct
26 Correct 31 ms 35576 KB Output is correct
27 Correct 31 ms 35576 KB Output is correct
28 Correct 31 ms 35576 KB Output is correct
29 Correct 30 ms 35576 KB Output is correct
30 Correct 31 ms 35576 KB Output is correct
31 Correct 31 ms 35576 KB Output is correct
32 Correct 49 ms 35588 KB Output is correct
33 Correct 31 ms 35576 KB Output is correct
34 Correct 32 ms 35576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 35576 KB Output is correct
2 Correct 31 ms 35576 KB Output is correct
3 Correct 41 ms 35532 KB Output is correct
4 Correct 35 ms 35576 KB Output is correct
5 Correct 31 ms 35484 KB Output is correct
6 Correct 38 ms 35576 KB Output is correct
7 Correct 31 ms 35576 KB Output is correct
8 Correct 30 ms 35576 KB Output is correct
9 Correct 31 ms 35576 KB Output is correct
10 Correct 31 ms 35652 KB Output is correct
11 Correct 31 ms 35576 KB Output is correct
12 Correct 31 ms 35596 KB Output is correct
13 Correct 31 ms 35704 KB Output is correct
14 Correct 31 ms 35576 KB Output is correct
15 Correct 30 ms 35576 KB Output is correct
16 Correct 30 ms 35580 KB Output is correct
17 Correct 31 ms 35704 KB Output is correct
18 Correct 31 ms 35576 KB Output is correct
19 Correct 31 ms 35576 KB Output is correct
20 Correct 31 ms 35576 KB Output is correct
21 Correct 31 ms 35576 KB Output is correct
22 Correct 31 ms 35576 KB Output is correct
23 Correct 31 ms 35576 KB Output is correct
24 Correct 38 ms 35576 KB Output is correct
25 Correct 32 ms 35576 KB Output is correct
26 Correct 31 ms 35576 KB Output is correct
27 Correct 31 ms 35576 KB Output is correct
28 Correct 31 ms 35576 KB Output is correct
29 Correct 30 ms 35576 KB Output is correct
30 Correct 31 ms 35576 KB Output is correct
31 Correct 31 ms 35576 KB Output is correct
32 Correct 49 ms 35588 KB Output is correct
33 Correct 31 ms 35576 KB Output is correct
34 Correct 32 ms 35576 KB Output is correct
35 Correct 32 ms 35704 KB Output is correct
36 Correct 37 ms 35680 KB Output is correct
37 Correct 33 ms 35736 KB Output is correct
38 Correct 37 ms 35704 KB Output is correct
39 Correct 37 ms 35676 KB Output is correct
40 Correct 39 ms 35704 KB Output is correct
41 Correct 31 ms 35704 KB Output is correct
42 Correct 32 ms 35724 KB Output is correct
43 Correct 31 ms 35704 KB Output is correct
44 Correct 31 ms 35708 KB Output is correct
45 Correct 31 ms 35704 KB Output is correct
46 Correct 32 ms 35708 KB Output is correct
47 Correct 31 ms 35704 KB Output is correct
48 Correct 31 ms 35704 KB Output is correct
49 Correct 31 ms 35832 KB Output is correct
50 Correct 31 ms 35704 KB Output is correct
51 Correct 31 ms 35704 KB Output is correct
52 Correct 31 ms 35664 KB Output is correct
53 Correct 32 ms 35832 KB Output is correct
54 Correct 31 ms 35632 KB Output is correct
55 Correct 31 ms 35656 KB Output is correct
56 Correct 31 ms 35704 KB Output is correct
57 Correct 32 ms 35712 KB Output is correct
58 Correct 31 ms 35704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 35576 KB Output is correct
2 Correct 30 ms 35548 KB Output is correct
3 Correct 31 ms 35576 KB Output is correct
4 Correct 31 ms 35576 KB Output is correct
5 Correct 31 ms 35576 KB Output is correct
6 Correct 39 ms 35576 KB Output is correct
7 Correct 247 ms 116728 KB Output is correct
8 Correct 254 ms 116984 KB Output is correct
9 Correct 277 ms 116988 KB Output is correct
10 Correct 255 ms 116952 KB Output is correct
11 Correct 268 ms 116984 KB Output is correct
12 Correct 262 ms 116984 KB Output is correct
13 Correct 248 ms 116960 KB Output is correct
14 Correct 254 ms 116912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 35576 KB Output is correct
2 Correct 31 ms 35576 KB Output is correct
3 Correct 41 ms 35532 KB Output is correct
4 Correct 35 ms 35576 KB Output is correct
5 Correct 31 ms 35484 KB Output is correct
6 Correct 38 ms 35576 KB Output is correct
7 Correct 31 ms 35576 KB Output is correct
8 Correct 30 ms 35576 KB Output is correct
9 Correct 31 ms 35576 KB Output is correct
10 Correct 31 ms 35652 KB Output is correct
11 Correct 31 ms 35576 KB Output is correct
12 Correct 31 ms 35596 KB Output is correct
13 Correct 31 ms 35704 KB Output is correct
14 Correct 31 ms 35576 KB Output is correct
15 Correct 30 ms 35576 KB Output is correct
16 Correct 30 ms 35580 KB Output is correct
17 Correct 31 ms 35704 KB Output is correct
18 Correct 31 ms 35576 KB Output is correct
19 Correct 31 ms 35576 KB Output is correct
20 Correct 31 ms 35576 KB Output is correct
21 Correct 31 ms 35576 KB Output is correct
22 Correct 31 ms 35576 KB Output is correct
23 Correct 31 ms 35576 KB Output is correct
24 Correct 38 ms 35576 KB Output is correct
25 Correct 32 ms 35576 KB Output is correct
26 Correct 31 ms 35576 KB Output is correct
27 Correct 31 ms 35576 KB Output is correct
28 Correct 31 ms 35576 KB Output is correct
29 Correct 30 ms 35576 KB Output is correct
30 Correct 31 ms 35576 KB Output is correct
31 Correct 31 ms 35576 KB Output is correct
32 Correct 49 ms 35588 KB Output is correct
33 Correct 31 ms 35576 KB Output is correct
34 Correct 32 ms 35576 KB Output is correct
35 Correct 32 ms 35704 KB Output is correct
36 Correct 37 ms 35680 KB Output is correct
37 Correct 33 ms 35736 KB Output is correct
38 Correct 37 ms 35704 KB Output is correct
39 Correct 37 ms 35676 KB Output is correct
40 Correct 39 ms 35704 KB Output is correct
41 Correct 31 ms 35704 KB Output is correct
42 Correct 32 ms 35724 KB Output is correct
43 Correct 31 ms 35704 KB Output is correct
44 Correct 31 ms 35708 KB Output is correct
45 Correct 31 ms 35704 KB Output is correct
46 Correct 32 ms 35708 KB Output is correct
47 Correct 31 ms 35704 KB Output is correct
48 Correct 31 ms 35704 KB Output is correct
49 Correct 31 ms 35832 KB Output is correct
50 Correct 31 ms 35704 KB Output is correct
51 Correct 31 ms 35704 KB Output is correct
52 Correct 31 ms 35664 KB Output is correct
53 Correct 32 ms 35832 KB Output is correct
54 Correct 31 ms 35632 KB Output is correct
55 Correct 31 ms 35656 KB Output is correct
56 Correct 31 ms 35704 KB Output is correct
57 Correct 32 ms 35712 KB Output is correct
58 Correct 31 ms 35704 KB Output is correct
59 Correct 30 ms 35576 KB Output is correct
60 Correct 30 ms 35548 KB Output is correct
61 Correct 31 ms 35576 KB Output is correct
62 Correct 31 ms 35576 KB Output is correct
63 Correct 31 ms 35576 KB Output is correct
64 Correct 39 ms 35576 KB Output is correct
65 Correct 247 ms 116728 KB Output is correct
66 Correct 254 ms 116984 KB Output is correct
67 Correct 277 ms 116988 KB Output is correct
68 Correct 255 ms 116952 KB Output is correct
69 Correct 268 ms 116984 KB Output is correct
70 Correct 262 ms 116984 KB Output is correct
71 Correct 248 ms 116960 KB Output is correct
72 Correct 254 ms 116912 KB Output is correct
73 Correct 239 ms 117772 KB Output is correct
74 Correct 280 ms 117856 KB Output is correct
75 Correct 252 ms 117864 KB Output is correct
76 Correct 251 ms 117672 KB Output is correct
77 Correct 259 ms 117704 KB Output is correct
78 Correct 258 ms 117752 KB Output is correct
79 Correct 259 ms 117764 KB Output is correct
80 Correct 256 ms 117880 KB Output is correct
81 Correct 255 ms 117752 KB Output is correct
82 Correct 255 ms 117880 KB Output is correct
83 Correct 254 ms 117784 KB Output is correct
84 Correct 252 ms 117752 KB Output is correct
85 Correct 254 ms 117752 KB Output is correct
86 Correct 255 ms 117880 KB Output is correct
87 Correct 254 ms 117752 KB Output is correct
88 Correct 253 ms 117752 KB Output is correct
89 Correct 254 ms 117880 KB Output is correct
90 Correct 254 ms 117752 KB Output is correct
91 Correct 280 ms 117724 KB Output is correct
92 Correct 279 ms 117804 KB Output is correct
93 Correct 288 ms 117884 KB Output is correct
94 Correct 273 ms 117752 KB Output is correct
95 Correct 270 ms 117668 KB Output is correct
96 Correct 269 ms 117752 KB Output is correct
97 Correct 268 ms 117752 KB Output is correct
98 Correct 270 ms 117784 KB Output is correct
99 Correct 269 ms 117880 KB Output is correct
100 Correct 292 ms 117752 KB Output is correct
101 Correct 272 ms 117752 KB Output is correct
102 Correct 272 ms 117756 KB Output is correct