답안 #110506

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110506 2019-05-11T05:02:16 Z AngusRitossa Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 23800 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;
			if (a[i] == (b[i]^t)) 
			{ 
				memo[i][t] = memo[i+1][t];
				continue;
			}
			int ans = memo[i+1][!t] + !t; // Remove/add a toggle, therefore curr is correct
			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 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 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 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 3 ms 384 KB Output isn't correct
14 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 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 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 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 3 ms 384 KB Output isn't correct
14 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 3 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 6 ms 384 KB Output is correct
7 Correct 128 ms 23800 KB Output is correct
8 Execution timed out 1078 ms 8900 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 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 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 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 3 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -