답안 #110502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110502 2019-05-11T04:51:51 Z AngusRitossa Lamps (JOI19_lamps) C++14
47 / 100
1000 ms 104148 KB
#include <bits/stdc++.h>
using namespace std;
int memo[1000010][2], done[1000010][2], a[1000010], b[1000010], n;
int dp(int i, int t)
{
	if (i == n) return 0;
	if (done[i][t]) return memo[i][t];
	done[i][t] = 1;
	if (a[i] == (b[i]^t)) return memo[i][t] = dp(i+1, t);
	int ans = dp(i+1, !t) + !t; // Remove/add a toggle, therefore curr is correct
	int extracost = 1, isok = 1, istoggled = t;
	for (int j = i; j < n; j++)
	{
		if ((b[j] == b[i]) != isok)
		{
			isok = !isok;
			istoggled = !istoggled;
			if (istoggled) extracost++;
		}
		int am = dp(j+1, istoggled)+extracost;
		ans = min(ans, am);
	}
	return memo[i][t] = ans;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) 
	{
		char c;
		scanf(" %c", &c);
		a[i] = c-'0';
	}
	for (int i = 0; i < n; i++) 
	{
		char c;
		scanf(" %c", &c);
		b[i] = c-'0';
	}
	int ans = dp(0, 0);
	printf("%d\n", ans);
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
lamp.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c", &c);
   ~~~~~^~~~~~~~~~~
lamp.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c", &c);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 284 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 284 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 18 ms 532 KB Output is correct
36 Correct 15 ms 512 KB Output is correct
37 Correct 15 ms 512 KB Output is correct
38 Correct 16 ms 512 KB Output is correct
39 Correct 17 ms 640 KB Output is correct
40 Correct 18 ms 512 KB Output is correct
41 Correct 16 ms 512 KB Output is correct
42 Correct 16 ms 512 KB Output is correct
43 Correct 17 ms 512 KB Output is correct
44 Correct 19 ms 640 KB Output is correct
45 Correct 20 ms 512 KB Output is correct
46 Correct 20 ms 512 KB Output is correct
47 Correct 25 ms 512 KB Output is correct
48 Correct 20 ms 512 KB Output is correct
49 Correct 22 ms 632 KB Output is correct
50 Correct 24 ms 512 KB Output is correct
51 Correct 24 ms 512 KB Output is correct
52 Correct 26 ms 512 KB Output is correct
53 Correct 22 ms 500 KB Output is correct
54 Correct 26 ms 512 KB Output is correct
55 Correct 32 ms 640 KB Output is correct
56 Correct 25 ms 588 KB Output is correct
57 Correct 23 ms 512 KB Output is correct
58 Correct 23 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 239 ms 104148 KB Output is correct
8 Execution timed out 1064 ms 96436 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 284 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 18 ms 532 KB Output is correct
36 Correct 15 ms 512 KB Output is correct
37 Correct 15 ms 512 KB Output is correct
38 Correct 16 ms 512 KB Output is correct
39 Correct 17 ms 640 KB Output is correct
40 Correct 18 ms 512 KB Output is correct
41 Correct 16 ms 512 KB Output is correct
42 Correct 16 ms 512 KB Output is correct
43 Correct 17 ms 512 KB Output is correct
44 Correct 19 ms 640 KB Output is correct
45 Correct 20 ms 512 KB Output is correct
46 Correct 20 ms 512 KB Output is correct
47 Correct 25 ms 512 KB Output is correct
48 Correct 20 ms 512 KB Output is correct
49 Correct 22 ms 632 KB Output is correct
50 Correct 24 ms 512 KB Output is correct
51 Correct 24 ms 512 KB Output is correct
52 Correct 26 ms 512 KB Output is correct
53 Correct 22 ms 500 KB Output is correct
54 Correct 26 ms 512 KB Output is correct
55 Correct 32 ms 640 KB Output is correct
56 Correct 25 ms 588 KB Output is correct
57 Correct 23 ms 512 KB Output is correct
58 Correct 23 ms 640 KB Output is correct
59 Correct 3 ms 384 KB Output is correct
60 Correct 2 ms 304 KB Output is correct
61 Correct 2 ms 384 KB Output is correct
62 Correct 4 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 3 ms 384 KB Output is correct
65 Correct 239 ms 104148 KB Output is correct
66 Execution timed out 1064 ms 96436 KB Time limit exceeded
67 Halted 0 ms 0 KB -