답안 #206012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206012 2020-03-01T23:48:33 Z mode149256 Lamps (JOI19_lamps) C++14
100 / 100
107 ms 59260 KB
/*input
17
10110110110110101
01011100100110000

6
011011
110010

17
10110110110110101
01011100100110000

6
011011
110010
// 4
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N;
	str A, B;
	cin >> N >> A >> B;

	vii dp(N, vi(3, MOD));
	// 0 - done
	// 1 - ones
	// 2 - zeroes

	dp[0][0] = (A[0] != B[0]);
	dp[0][1] = 1 + (B[0] == '0');
	dp[0][2] = 1 + (B[0] == '1');

	for (int i = 1; i < N; ++i)
	{
		// pildom [0]
		dp[i][0] = min(dp[i][0], dp[i - 1][0] + (A[i] != B[i] and A[i - 1] == B[i - 1]));
		dp[i][0] = min(dp[i][0], dp[i - 1][1] + (A[i] != B[i] and B[i - 1] == '1'));
		dp[i][0] = min(dp[i][0], dp[i - 1][2] + (A[i] != B[i] and B[i - 1] == '0'));
		// dp[i][0] = min(dp[i][0], dp[i - 1][0] + (A[i] != B[i] and A[i - 1] == B[i - 1]));
		// dp[i][0] = min(dp[i][0], dp[i - 1][2] + (B[i] == '1' and B[i - 1] != '1'));

		// pildom [1]
		dp[i][1] = min(dp[i][1], dp[i - 1][0] + 1 + (B[i] == '0' and A[i - 1] == B[i - 1]));
		dp[i][1] = min(dp[i][1], dp[i - 1][1] + (B[i] == '0' and B[i - 1] != '0'));
		// dp[i][1] = min(dp[i][1], dp[i - 1][2] + (B[i] == '0'));


		dp[i][2] = min(dp[i][2], dp[i - 1][0] + 1 + (B[i] == '1' and A[i - 1] == B[i - 1]));
		dp[i][2] = min(dp[i][2], dp[i - 1][2] + (B[i] == '1' and B[i - 1] != '1'));
	}

	// print(dp);
	// for (int i = 0; i < N; ++i) printf("%d", dp[i][0]); printf("\n");
	// for (int i = 0; i < N; ++i) printf("%d", dp[i][1]); printf("\n");
	// for (int i = 0; i < N; ++i) printf("%d", dp[i][2]); printf("\n");

	printf("%d\n", min(dp[N - 1][0], min(dp[N - 1][1], dp[N - 1][2])));
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 504 KB Output is correct
36 Correct 5 ms 504 KB Output is correct
37 Correct 5 ms 504 KB Output is correct
38 Correct 6 ms 376 KB Output is correct
39 Correct 5 ms 504 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 5 ms 504 KB Output is correct
42 Correct 5 ms 504 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 5 ms 508 KB Output is correct
45 Correct 5 ms 380 KB Output is correct
46 Correct 5 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 6 ms 504 KB Output is correct
49 Correct 5 ms 504 KB Output is correct
50 Correct 5 ms 504 KB Output is correct
51 Correct 5 ms 504 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 5 ms 504 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 5 ms 504 KB Output is correct
56 Correct 5 ms 504 KB Output is correct
57 Correct 5 ms 504 KB Output is correct
58 Correct 5 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 84 ms 57288 KB Output is correct
8 Correct 82 ms 57156 KB Output is correct
9 Correct 81 ms 57160 KB Output is correct
10 Correct 83 ms 57160 KB Output is correct
11 Correct 82 ms 57160 KB Output is correct
12 Correct 82 ms 57036 KB Output is correct
13 Correct 82 ms 57156 KB Output is correct
14 Correct 85 ms 57036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 504 KB Output is correct
36 Correct 5 ms 504 KB Output is correct
37 Correct 5 ms 504 KB Output is correct
38 Correct 6 ms 376 KB Output is correct
39 Correct 5 ms 504 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 5 ms 504 KB Output is correct
42 Correct 5 ms 504 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 5 ms 508 KB Output is correct
45 Correct 5 ms 380 KB Output is correct
46 Correct 5 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 6 ms 504 KB Output is correct
49 Correct 5 ms 504 KB Output is correct
50 Correct 5 ms 504 KB Output is correct
51 Correct 5 ms 504 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 5 ms 504 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 5 ms 504 KB Output is correct
56 Correct 5 ms 504 KB Output is correct
57 Correct 5 ms 504 KB Output is correct
58 Correct 5 ms 508 KB Output is correct
59 Correct 5 ms 248 KB Output is correct
60 Correct 5 ms 376 KB Output is correct
61 Correct 5 ms 376 KB Output is correct
62 Correct 4 ms 376 KB Output is correct
63 Correct 5 ms 376 KB Output is correct
64 Correct 5 ms 376 KB Output is correct
65 Correct 84 ms 57288 KB Output is correct
66 Correct 82 ms 57156 KB Output is correct
67 Correct 81 ms 57160 KB Output is correct
68 Correct 83 ms 57160 KB Output is correct
69 Correct 82 ms 57160 KB Output is correct
70 Correct 82 ms 57036 KB Output is correct
71 Correct 82 ms 57156 KB Output is correct
72 Correct 85 ms 57036 KB Output is correct
73 Correct 85 ms 59080 KB Output is correct
74 Correct 83 ms 59080 KB Output is correct
75 Correct 84 ms 59044 KB Output is correct
76 Correct 83 ms 59084 KB Output is correct
77 Correct 81 ms 59080 KB Output is correct
78 Correct 82 ms 59080 KB Output is correct
79 Correct 90 ms 59212 KB Output is correct
80 Correct 85 ms 59084 KB Output is correct
81 Correct 82 ms 59076 KB Output is correct
82 Correct 83 ms 59084 KB Output is correct
83 Correct 88 ms 59120 KB Output is correct
84 Correct 90 ms 59084 KB Output is correct
85 Correct 88 ms 59112 KB Output is correct
86 Correct 87 ms 59080 KB Output is correct
87 Correct 90 ms 59172 KB Output is correct
88 Correct 89 ms 59084 KB Output is correct
89 Correct 88 ms 59084 KB Output is correct
90 Correct 100 ms 59084 KB Output is correct
91 Correct 93 ms 59260 KB Output is correct
92 Correct 107 ms 59076 KB Output is correct
93 Correct 93 ms 59072 KB Output is correct
94 Correct 95 ms 59084 KB Output is correct
95 Correct 100 ms 59200 KB Output is correct
96 Correct 94 ms 59076 KB Output is correct
97 Correct 94 ms 59080 KB Output is correct
98 Correct 91 ms 59084 KB Output is correct
99 Correct 102 ms 59212 KB Output is correct
100 Correct 92 ms 59084 KB Output is correct
101 Correct 94 ms 59084 KB Output is correct
102 Correct 91 ms 59084 KB Output is correct