Submission #373128

# Submission time Handle Problem Language Result Execution time Memory
373128 2021-03-03T13:29:46 Z luciocf Lamps (JOI19_lamps) C++14
0 / 100
2 ms 492 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e3+10;

char a[maxn], b[maxn];

int solve[maxn][maxn][2];

int dp[maxn];

int main(void)
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf(" %c", &a[i]);

	for (int i = 1;  i <= n; i++)
		scanf(" %c", &b[i]);

	for (int l = 1; l <= n; l++)
	{
		solve[l][l][0] = (b[l] == '0' ? 0 : 1);

		for (int r = l+1; r <= n; r++)
		{
			if (b[r] == '0' || b[r-1] == '1') solve[l][r][0] = solve[l][r-1][0];
			else solve[l][r][0] = solve[l][r-1][0]+1;
		}

		solve[l][l][1] = (b[l] == '1' ? 0 : 1);

		for (int r = l+1; r <= n; r++)
		{
			if (b[r] == '1' || b[r-1] == '0') solve[l][r][1] = solve[l][r-1][1];
			else solve[l][r][1] = solve[l][r-1][1]+1;
		}
	}

	for (int i = 1; i <= n; i++)
	{
		dp[i] = n+1;

		if (a[i] == b[i]) dp[i] = min(dp[i], dp[i-1]);

		for (int j = i-1; j >= 0 && a[j+1] != b[j+1]; j--)
			dp[i] = min(dp[i], 1 + dp[j]);

		bool zero = 0, um = 0;

		for (int j = i-1; j >= 0; j--)
		{
			zero |= (a[j+1] == '0');
			um |= (a[j+1] == '1');

			dp[i] = min(dp[i], (um ? 1 : 0) + solve[j+1][i][0] + dp[j]);
			dp[i] = min(dp[i], (zero ? 1 : 0) + solve[j+1][i][1] + dp[j]);
		}
	}

	printf("%d\n", dp[n]);
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
lamp.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf(" %c", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~
lamp.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |   scanf(" %c", &b[i]);
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Execution timed out 2 ms 364 KB Time limit exceeded (wall clock)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -