답안 #143624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143624 2019-08-14T18:35:27 Z godwind Lamps (JOI19_lamps) C++17
4 / 100
94 ms 43452 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                        
using namespace std;
                        
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                        
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
 
#define ghost signed
#define left left228
#define right right228
#define complex complex228
#define count count228
#define sin sin228
#define list list228

const int N = 1000 * 1000 + 228;
const int INF = 1e9 + 228;

int n;
int s[N], t[N];
int dp[N][3][2];
int color[N][3];
/*
0 - none
1 - color 0
2 - color 1
*/

ghost main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cin >> n;
	char chaaa;
	for (int i = 1; i <= n; ++i) {
		cin >> chaaa;
		s[i] = (chaaa - '0');
	}
	for (int i = 1; i <= n; ++i) {
		cin >> chaaa;
		t[i] = (chaaa - '0');
	}
	for (int i = 1; i <= n; ++i) {
		color[i][0] = s[i];
		color[i][1] = 0;
		color[i][2] = 1;
	}
	for (int i = 1; i <= n; ++i) {
		for (int c1 = 0; c1 < 3; ++c1) {
			for (int c2 = 0; c2 < 2; ++c2) {
				dp[i][c1][c2] = INF;
			}
		}
	}
	for (int c1 = 0; c1 < 3; ++c1) {
		for (int c2 = 0; c2 < 1; ++c2) {
			if ((color[1][c1] ^ c2) == t[1]) {
				dp[1][c1][c2] = (c1 > 0) + (c2 > 0);
			}
		}
	}
	for (int i = 1; i < n; ++i) {
		for (int c1 = 0; c1 < 3; ++c1) {
			for (int c2 = 0; c2 < 2; ++c2) {
				if (dp[i][c1][c2] == INF) continue;
				for (int b1 = 0; b1 < 3; ++b1) {
					for (int b2 = 0; b2 < 2; ++b2) {
						if ((color[i + 1][b1] ^ b2) != t[i + 1]) continue;
						uin(dp[i + 1][b1][b2], dp[i][c1][c2] + (b1 && b1 != c1) + (b2 && b2 != c2));
					}
				}
			}
		}
	}
	int res = INF;
	for (int c1 = 0; c1 < 3; ++c1) {
		for (int c2 = 0; c2 < 2; ++c2) uin(res, dp[n][c1][c2]);
	}
	cout << res << '\n';
    return 0;
} // kek ;
// Ого! Кажетсья это $#@!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 86 ms 43356 KB Output is correct
8 Correct 89 ms 43384 KB Output is correct
9 Correct 91 ms 43444 KB Output is correct
10 Correct 94 ms 43376 KB Output is correct
11 Correct 90 ms 43452 KB Output is correct
12 Correct 89 ms 43416 KB Output is correct
13 Correct 87 ms 43360 KB Output is correct
14 Correct 88 ms 43388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -