답안 #110510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110510 2019-05-11T05:05:31 Z AngusRitossa Lamps (JOI19_lamps) C++14
47 / 100
1000 ms 23864 KB
#include <bits/stdc++.h>
using namespace std;
int memo[1000010][2], done[1000010][2], a[1000010], b[1000010], n, loopcost[1000010][2];

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';
	}
	for (int i = n-1; i >= 0; i--)
	{
		for (int t = 0; t < 2; t++)
		{
			loopcost[i][t] = 1e9;
			int ans = 1e9;
			if (a[i] == (b[i]^t)) 
			{ 
				ans = min(ans, memo[i+1][t]);
			}
			else ans = min(ans, memo[i+1][!t] + !t); 
			int extracost = 1, isok = 1, istoggled = t;
			if (i != n-1 && b[i+1] == b[i])
			{
				loopcost[i][t] = memo[i+1][t]+1;
				loopcost[i][t] = min(loopcost[i][t], loopcost[i+1][t]);
			}
			else
			{
				for (int j = i; j < n; j++)
				{
					if ((b[j] == b[i]) != isok)
					{
						isok = !isok;
						istoggled = !istoggled;
						if (istoggled) extracost++;
					}
					int am = memo[j+1][istoggled]+extracost;
					loopcost[i][t] = min(loopcost[i][t], am);
				}
			}
			ans = min(ans, loopcost[i][t]);
		 	memo[i][t] = ans;
		}
	}
	int ans = memo[0][0];
	printf("%d\n", ans);
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
lamp.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c", &c);
   ~~~~~^~~~~~~~~~~
lamp.cpp:17: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 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 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 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 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 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 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 3 ms 384 KB Output is correct
30 Correct 2 ms 384 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 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 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 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 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 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 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 3 ms 384 KB Output is correct
30 Correct 2 ms 384 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 12 ms 428 KB Output is correct
36 Correct 10 ms 384 KB Output is correct
37 Correct 12 ms 384 KB Output is correct
38 Correct 9 ms 256 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 7 ms 384 KB Output is correct
48 Correct 6 ms 384 KB Output is correct
49 Correct 8 ms 384 KB Output is correct
50 Correct 10 ms 384 KB Output is correct
51 Correct 11 ms 384 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 9 ms 384 KB Output is correct
54 Correct 7 ms 384 KB Output is correct
55 Correct 8 ms 512 KB Output is correct
56 Correct 8 ms 384 KB Output is correct
57 Correct 8 ms 384 KB Output is correct
58 Correct 9 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 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 356 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 160 ms 23864 KB Output is correct
8 Execution timed out 1067 ms 8708 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 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 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 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 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 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 3 ms 384 KB Output is correct
30 Correct 2 ms 384 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 12 ms 428 KB Output is correct
36 Correct 10 ms 384 KB Output is correct
37 Correct 12 ms 384 KB Output is correct
38 Correct 9 ms 256 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 7 ms 384 KB Output is correct
48 Correct 6 ms 384 KB Output is correct
49 Correct 8 ms 384 KB Output is correct
50 Correct 10 ms 384 KB Output is correct
51 Correct 11 ms 384 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 9 ms 384 KB Output is correct
54 Correct 7 ms 384 KB Output is correct
55 Correct 8 ms 512 KB Output is correct
56 Correct 8 ms 384 KB Output is correct
57 Correct 8 ms 384 KB Output is correct
58 Correct 9 ms 384 KB Output is correct
59 Correct 3 ms 384 KB Output is correct
60 Correct 2 ms 384 KB Output is correct
61 Correct 2 ms 384 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 2 ms 356 KB Output is correct
64 Correct 3 ms 384 KB Output is correct
65 Correct 160 ms 23864 KB Output is correct
66 Execution timed out 1067 ms 8708 KB Time limit exceeded
67 Halted 0 ms 0 KB -