답안 #261309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261309 2020-08-11T16:04:26 Z mjkocijan Lamps (JOI19_lamps) C++14
4 / 100
57 ms 41496 KB
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
#define MAXN 1001001

int n, reza = 0, reza2 = 0;
char a[MAXN], b[MAXN];
int fl[MAXN], t0[MAXN], t1[MAXN], fif[MAXN], fib[MAXN], cf[MAXN], c0[MAXN], c1[MAXN], cfr[MAXN];
int alt_reza = 0;
int gotu[MAXN];

int main()
{
	memset(gotu, -1, sizeof gotu);
	scanf("%d", &n);
	scanf("%s", a);
	scanf("%s", b);
	for (int i = 0; i < n; i++) {
		fl[i] = a[i] != b[i];
		t0[i] = b[i] == '0';
		t1[i] = b[i] == '1';
	}
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			fif[i] = 0;
			fib[i] = 0;
		} else {
			if (fl[i]) fif[i] = fl[i - 1] ? fif[i - 1] : i;
			fib[i] = t0[i - 1] == t0[i] ? fib[i - 1] : i;
			cf[i] = cf[i - 1];
			c0[i] = c0[i - 1];
			c1[i] = c1[i - 1];
		}
		if ((i == n - 1 && fl[i]) || (i < n - 1 && fl[i] && !fl[i + 1])) {
			cf[i]++;
		}
		if (i == n - 1 || (i < n - 1 && t0[i] && !t0[i + 1])) {
			c0[i]++;
			alt_reza++;
		}
		if (i == n - 1 || (i < n - 1 && t1[i] && !t1[i + 1])) {
			c1[i]++;
			if (i < n - 1) alt_reza++;
		}
		//cout << i<<": "<<fl[i]<<' '<<t0[i]<<' '<<t1[i]<<' '<<fif[i]<<' '<<fib[i]<<' '<<cf[i]<<' '<<c0[i]<<' '<<c1[i]<<endl;
	}
	for (int i = n - 1; i >= 0; i--) {
		if (i < n - 1) {
			cfr[i] = cfr[i + 1];
		}
		if ((!i && fl[i]) || (i && fl[i] && !fl[i - 1])) {
			cfr[i]++;
		}
	}
	//for (int i = 0; i < n; i++) {
		//cout << fl[i] << ' ' << cfr[i]<<' '<<cf[i]<<endl;
	//}//
	/*for (int i = 0; i < n; i++) {
		if (i < n - 1 && fl[i] == fl[i + 1]) continue;
		if (!fl[i]) continue;
		reza++;//cout<<i<<' ';
	}//cout<<endl;
	int i2 = 0, i3 = 0;
	for (; i2 < n; i2++) {
		if (t0[i2]) break;
	}
	for (; i3 < n; i3++) {
		if (t1[i3]) break;
	}
	if (max(i2 - 1, i3 - 1) >= 0) reza -= max(0, cf[max(i2 - 1, i3 - 1)] - 1);//printf("%d\n", reza);
	i2 = n - 1; i3 = n - 1;
	for (; i2 >= 0; i2--) {
		if (t0[i2]) break;
	}
	for (; i3 >= 0; i3--) {
		if (t1[i3]) break;
	}
	if (min(i2 + 1, i3 + 1) < n && i2 >= 0 && i3 >= 0) reza -= max(0, cfr[min(i2 + 1, i3 + 1)] - 1);//printf("%d\n", reza);
	for (int i = 0; i < n; i++) {
		if (!t1[i] || (i < n - 1 && t1[i + 1])) continue;
		if (i == n - 1 || fib[i] == 0) continue;
		int ccc = fl[fib[i]];
		if (fl[fib[i] - 1] && fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - ccc);//cout<<i<<'.'<<reza<<' '<<fib[i]<<' '<<fl[fib[i]-1]<<' '<<cf[i]<<' '<<cf[fib[i]-1]<<' '<<ccc<<endl;
		if (!fl[fib[i] - 1] && fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - 1);//cout<<i<<'.'<<reza<<endl;
		if (fl[fib[i] - 1] && !fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - ccc - 1);//cout<<i<<'.'<<reza<<endl;
		if (!fl[fib[i] - 1] && !fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - 1);//cout<<i<<'.'<<reza<<endl;
	}printf("%d\n", reza);
	for (int i = 0; i < n; i++) {
		if (!t0[i] || (i < n - 1 && t0[i + 1])) continue;
		if (i == n - 1 || fib[i] == 0) continue;
		int ccc = fl[fib[i]];
		if (fl[fib[i] - 1] && fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - ccc);
		if (!fl[fib[i] - 1] && fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - 1);
		if (fl[fib[i] - 1] && !fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - ccc - 1);
		if (!fl[fib[i] - 1] && !fl[i + 1]) reza -= max(0, cf[i] - cf[fib[i] - 1] - 1);
	}*/
	for (int i = 0; i < n; i++) {
		//if (i < n - 1) continue;
		if (i < n - 1 && t0[i] == t0[i + 1]) continue;
		//cout <<i <<' '<<fib[i]<<endl;
		if ((cf[i] != cf[fib[i]] && cfr[i] != cfr[fib[i]]) || (fl[fib[i]] && fl[i] && fif[i] != fif[fib[i]])) {
		//if (cf[i] != cf[fib[i]] || cfr[i] != cfr[fib[i]]) {
			gotu[fib[i]] = i;//cout<<i<<' '<<fib[i]<<" . "<<cf[i]<<' '<<cf[fib[i]]<<endl;
			reza2++;
			//for (int j = fib[i]; j <= i; j++) {
			//	
			//}
		}
	}
	int kile = 0;
	for (int i = 0; i < n; i++) {
		if (gotu[i] > -1) {
			i = gotu[i];
			continue;
		}
		if (!fl[i]) { reza += kile; kile = 0; continue; }
		if (i < n - 1 && gotu[i + 1] > -1) {kile = 1; continue;}
		if (i < n - 1 && fl[i] == fl[i + 1]) continue;
		reza++;
		kile = 0;
		//cout<<i<<' ';
	}
	//reza = min(reza, alt_reza);
	printf("%d\n", reza + reza2 + kile);
	return 0;
}
/*
29
10000101101100111110001110010
11101110000111000011110001101
*/

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
lamp.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", a);
  ~~~~~^~~~~~~~~
lamp.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", b);
  ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4352 KB Output is correct
2 Correct 3 ms 4352 KB Output is correct
3 Correct 3 ms 4352 KB Output is correct
4 Correct 3 ms 4352 KB Output is correct
5 Correct 3 ms 4352 KB Output is correct
6 Correct 3 ms 4352 KB Output is correct
7 Correct 3 ms 4352 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 4 ms 4352 KB Output is correct
10 Correct 3 ms 4352 KB Output is correct
11 Correct 3 ms 4352 KB Output is correct
12 Correct 3 ms 4352 KB Output is correct
13 Correct 3 ms 4352 KB Output is correct
14 Correct 3 ms 4352 KB Output is correct
15 Correct 3 ms 4352 KB Output is correct
16 Incorrect 3 ms 4352 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4352 KB Output is correct
2 Correct 3 ms 4352 KB Output is correct
3 Correct 3 ms 4352 KB Output is correct
4 Correct 3 ms 4352 KB Output is correct
5 Correct 3 ms 4352 KB Output is correct
6 Correct 3 ms 4352 KB Output is correct
7 Correct 3 ms 4352 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 4 ms 4352 KB Output is correct
10 Correct 3 ms 4352 KB Output is correct
11 Correct 3 ms 4352 KB Output is correct
12 Correct 3 ms 4352 KB Output is correct
13 Correct 3 ms 4352 KB Output is correct
14 Correct 3 ms 4352 KB Output is correct
15 Correct 3 ms 4352 KB Output is correct
16 Incorrect 3 ms 4352 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4352 KB Output is correct
2 Correct 3 ms 4352 KB Output is correct
3 Correct 3 ms 4480 KB Output is correct
4 Correct 3 ms 4352 KB Output is correct
5 Correct 3 ms 4352 KB Output is correct
6 Correct 3 ms 4352 KB Output is correct
7 Correct 44 ms 37496 KB Output is correct
8 Correct 57 ms 41496 KB Output is correct
9 Correct 48 ms 41464 KB Output is correct
10 Correct 48 ms 41464 KB Output is correct
11 Correct 49 ms 41464 KB Output is correct
12 Correct 47 ms 41396 KB Output is correct
13 Correct 43 ms 40184 KB Output is correct
14 Correct 43 ms 41464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4352 KB Output is correct
2 Correct 3 ms 4352 KB Output is correct
3 Correct 3 ms 4352 KB Output is correct
4 Correct 3 ms 4352 KB Output is correct
5 Correct 3 ms 4352 KB Output is correct
6 Correct 3 ms 4352 KB Output is correct
7 Correct 3 ms 4352 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 4 ms 4352 KB Output is correct
10 Correct 3 ms 4352 KB Output is correct
11 Correct 3 ms 4352 KB Output is correct
12 Correct 3 ms 4352 KB Output is correct
13 Correct 3 ms 4352 KB Output is correct
14 Correct 3 ms 4352 KB Output is correct
15 Correct 3 ms 4352 KB Output is correct
16 Incorrect 3 ms 4352 KB Output isn't correct
17 Halted 0 ms 0 KB -