Submission #105081

#TimeUsernameProblemLanguageResultExecution timeMemory
105081Just_Solve_The_ProblemLamps (JOI19_lamps)C++11
100 / 100
155 ms16636 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e6 + 7;

string a, b;
int n;
int dp[N][3];
/*
dp[pos][operation]
operation
0 = off
1 = on
2 = do not touch
*/

char make(char c, int i) {
	if (i < 2) return i + '0';
	return c;
}

main() {
	memset(dp, 63, sizeof dp);
	scanf("%d", &n);
	cin >> a >> b;
	a = " " + a;
	b = " " + b;
	dp[0][2] = 0;
	int cost;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int l = 0; l < 3; l++) {
				cost = dp[i - 1][j];
				if (j != l && l != 2)
					cost++;
				if ((i == 1 || make(a[i - 1], j) == b[i - 1]) && make(a[i], l) != b[i])
					cost++;
				dp[i][l] = min(dp[i][l], cost);
			}
		}
	}
	printf("%d\n", min(dp[n][0], min(dp[n][1], dp[n][2])));
}

Compilation message (stderr)

lamp.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
lamp.cpp: In function 'int main()':
lamp.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...