답안 #483173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483173 2021-10-28T03:17:39 Z hollwo_pelw Lamps (JOI19_lamps) C++17
100 / 100
27 ms 14016 KB
/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
	if (fopen(filein.c_str(), "r")){
		freopen(filein.c_str(), "r", stdin);
		freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
		freopen(fileerr.c_str(), "w", stderr);
#endif
	}
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}

void Hollwo_Pelw();

signed main(){
#ifdef hollwo_pelw_local
	FAST_IO("input.inp", "output.out", "error.err");
	auto start = chrono::steady_clock::now();
#else
	FAST_IO("JOI19_lamps.inp", "JOI19_lamps.out");
#endif
	int testcases = 1;
	// cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = chrono::steady_clock::now();
	cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
	return 0;
}

const int N = 1e6 + 5;

// 0 = nothing
// 1 = set 0
// 2 = set 1
// -> !eq ? flip : not

int n, dp[N][3];
char a[N], b[N];

inline void chkmin(int &a, int b) { a = a < b ? a : b; }

void Hollwo_Pelw() {
	cin >> n >> (a + 1) >> (b + 1);
	memset(dp, 0x3f, sizeof dp);

	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) for (int j = 0; j < 3; j++) {
		char cur = !j ? a[i] : (j - 1 + '0');
		bool flip = cur != b[i];

		chkmin(dp[i][j], dp[i - 1][0]
			+ (a[i - 1] == b[i - 1]) * flip // start flip
			+ (j != 0) // start set (0 / 1)
		);

		chkmin(dp[i][j], dp[i - 1][1]
			+ (i == 1 || b[i - 1] == '0') * flip // start flip
			+ (j == 2) // start set (0 / 1)
		);

		chkmin(dp[i][j], dp[i - 1][2]
			+ (i == 1 || b[i - 1] == '1') * flip // start flip
			+ (j == 1) // start set (0 / 1)
		);
	}

	cout << *min_element(dp[n], dp[n] + 3);
}

Compilation message

lamp.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
lamp.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11980 KB Output is correct
2 Correct 5 ms 11980 KB Output is correct
3 Correct 4 ms 11980 KB Output is correct
4 Correct 5 ms 11980 KB Output is correct
5 Correct 5 ms 11996 KB Output is correct
6 Correct 6 ms 12016 KB Output is correct
7 Correct 5 ms 11980 KB Output is correct
8 Correct 5 ms 11980 KB Output is correct
9 Correct 5 ms 11980 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 5 ms 11980 KB Output is correct
12 Correct 5 ms 11980 KB Output is correct
13 Correct 5 ms 11980 KB Output is correct
14 Correct 5 ms 11980 KB Output is correct
15 Correct 5 ms 11980 KB Output is correct
16 Correct 6 ms 12060 KB Output is correct
17 Correct 4 ms 11980 KB Output is correct
18 Correct 4 ms 11980 KB Output is correct
19 Correct 4 ms 11980 KB Output is correct
20 Correct 4 ms 11980 KB Output is correct
21 Correct 4 ms 11992 KB Output is correct
22 Correct 4 ms 11980 KB Output is correct
23 Correct 6 ms 11980 KB Output is correct
24 Correct 5 ms 11980 KB Output is correct
25 Correct 6 ms 11980 KB Output is correct
26 Correct 4 ms 11980 KB Output is correct
27 Correct 7 ms 11980 KB Output is correct
28 Correct 5 ms 11980 KB Output is correct
29 Correct 5 ms 11980 KB Output is correct
30 Correct 4 ms 11980 KB Output is correct
31 Correct 5 ms 11980 KB Output is correct
32 Correct 5 ms 12056 KB Output is correct
33 Correct 5 ms 12020 KB Output is correct
34 Correct 4 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11980 KB Output is correct
2 Correct 5 ms 11980 KB Output is correct
3 Correct 4 ms 11980 KB Output is correct
4 Correct 5 ms 11980 KB Output is correct
5 Correct 5 ms 11996 KB Output is correct
6 Correct 6 ms 12016 KB Output is correct
7 Correct 5 ms 11980 KB Output is correct
8 Correct 5 ms 11980 KB Output is correct
9 Correct 5 ms 11980 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 5 ms 11980 KB Output is correct
12 Correct 5 ms 11980 KB Output is correct
13 Correct 5 ms 11980 KB Output is correct
14 Correct 5 ms 11980 KB Output is correct
15 Correct 5 ms 11980 KB Output is correct
16 Correct 6 ms 12060 KB Output is correct
17 Correct 4 ms 11980 KB Output is correct
18 Correct 4 ms 11980 KB Output is correct
19 Correct 4 ms 11980 KB Output is correct
20 Correct 4 ms 11980 KB Output is correct
21 Correct 4 ms 11992 KB Output is correct
22 Correct 4 ms 11980 KB Output is correct
23 Correct 6 ms 11980 KB Output is correct
24 Correct 5 ms 11980 KB Output is correct
25 Correct 6 ms 11980 KB Output is correct
26 Correct 4 ms 11980 KB Output is correct
27 Correct 7 ms 11980 KB Output is correct
28 Correct 5 ms 11980 KB Output is correct
29 Correct 5 ms 11980 KB Output is correct
30 Correct 4 ms 11980 KB Output is correct
31 Correct 5 ms 11980 KB Output is correct
32 Correct 5 ms 12056 KB Output is correct
33 Correct 5 ms 12020 KB Output is correct
34 Correct 4 ms 11980 KB Output is correct
35 Correct 4 ms 11980 KB Output is correct
36 Correct 5 ms 11980 KB Output is correct
37 Correct 5 ms 12016 KB Output is correct
38 Correct 5 ms 11980 KB Output is correct
39 Correct 5 ms 11980 KB Output is correct
40 Correct 5 ms 11980 KB Output is correct
41 Correct 6 ms 11980 KB Output is correct
42 Correct 5 ms 11980 KB Output is correct
43 Correct 4 ms 11980 KB Output is correct
44 Correct 4 ms 11980 KB Output is correct
45 Correct 4 ms 11980 KB Output is correct
46 Correct 4 ms 11980 KB Output is correct
47 Correct 5 ms 11956 KB Output is correct
48 Correct 4 ms 11980 KB Output is correct
49 Correct 5 ms 11980 KB Output is correct
50 Correct 7 ms 12032 KB Output is correct
51 Correct 5 ms 11980 KB Output is correct
52 Correct 5 ms 11980 KB Output is correct
53 Correct 5 ms 11964 KB Output is correct
54 Correct 4 ms 11980 KB Output is correct
55 Correct 4 ms 11948 KB Output is correct
56 Correct 4 ms 11980 KB Output is correct
57 Correct 4 ms 11980 KB Output is correct
58 Correct 4 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11980 KB Output is correct
2 Correct 5 ms 11980 KB Output is correct
3 Correct 5 ms 11980 KB Output is correct
4 Correct 5 ms 11980 KB Output is correct
5 Correct 5 ms 11980 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 20 ms 13900 KB Output is correct
8 Correct 21 ms 14012 KB Output is correct
9 Correct 20 ms 14012 KB Output is correct
10 Correct 22 ms 13960 KB Output is correct
11 Correct 20 ms 13900 KB Output is correct
12 Correct 20 ms 14012 KB Output is correct
13 Correct 20 ms 13900 KB Output is correct
14 Correct 26 ms 14008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11980 KB Output is correct
2 Correct 5 ms 11980 KB Output is correct
3 Correct 4 ms 11980 KB Output is correct
4 Correct 5 ms 11980 KB Output is correct
5 Correct 5 ms 11996 KB Output is correct
6 Correct 6 ms 12016 KB Output is correct
7 Correct 5 ms 11980 KB Output is correct
8 Correct 5 ms 11980 KB Output is correct
9 Correct 5 ms 11980 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 5 ms 11980 KB Output is correct
12 Correct 5 ms 11980 KB Output is correct
13 Correct 5 ms 11980 KB Output is correct
14 Correct 5 ms 11980 KB Output is correct
15 Correct 5 ms 11980 KB Output is correct
16 Correct 6 ms 12060 KB Output is correct
17 Correct 4 ms 11980 KB Output is correct
18 Correct 4 ms 11980 KB Output is correct
19 Correct 4 ms 11980 KB Output is correct
20 Correct 4 ms 11980 KB Output is correct
21 Correct 4 ms 11992 KB Output is correct
22 Correct 4 ms 11980 KB Output is correct
23 Correct 6 ms 11980 KB Output is correct
24 Correct 5 ms 11980 KB Output is correct
25 Correct 6 ms 11980 KB Output is correct
26 Correct 4 ms 11980 KB Output is correct
27 Correct 7 ms 11980 KB Output is correct
28 Correct 5 ms 11980 KB Output is correct
29 Correct 5 ms 11980 KB Output is correct
30 Correct 4 ms 11980 KB Output is correct
31 Correct 5 ms 11980 KB Output is correct
32 Correct 5 ms 12056 KB Output is correct
33 Correct 5 ms 12020 KB Output is correct
34 Correct 4 ms 11980 KB Output is correct
35 Correct 4 ms 11980 KB Output is correct
36 Correct 5 ms 11980 KB Output is correct
37 Correct 5 ms 12016 KB Output is correct
38 Correct 5 ms 11980 KB Output is correct
39 Correct 5 ms 11980 KB Output is correct
40 Correct 5 ms 11980 KB Output is correct
41 Correct 6 ms 11980 KB Output is correct
42 Correct 5 ms 11980 KB Output is correct
43 Correct 4 ms 11980 KB Output is correct
44 Correct 4 ms 11980 KB Output is correct
45 Correct 4 ms 11980 KB Output is correct
46 Correct 4 ms 11980 KB Output is correct
47 Correct 5 ms 11956 KB Output is correct
48 Correct 4 ms 11980 KB Output is correct
49 Correct 5 ms 11980 KB Output is correct
50 Correct 7 ms 12032 KB Output is correct
51 Correct 5 ms 11980 KB Output is correct
52 Correct 5 ms 11980 KB Output is correct
53 Correct 5 ms 11964 KB Output is correct
54 Correct 4 ms 11980 KB Output is correct
55 Correct 4 ms 11948 KB Output is correct
56 Correct 4 ms 11980 KB Output is correct
57 Correct 4 ms 11980 KB Output is correct
58 Correct 4 ms 11980 KB Output is correct
59 Correct 5 ms 11980 KB Output is correct
60 Correct 5 ms 11980 KB Output is correct
61 Correct 5 ms 11980 KB Output is correct
62 Correct 5 ms 11980 KB Output is correct
63 Correct 5 ms 11980 KB Output is correct
64 Correct 6 ms 11980 KB Output is correct
65 Correct 20 ms 13900 KB Output is correct
66 Correct 21 ms 14012 KB Output is correct
67 Correct 20 ms 14012 KB Output is correct
68 Correct 22 ms 13960 KB Output is correct
69 Correct 20 ms 13900 KB Output is correct
70 Correct 20 ms 14012 KB Output is correct
71 Correct 20 ms 13900 KB Output is correct
72 Correct 26 ms 14008 KB Output is correct
73 Correct 24 ms 14012 KB Output is correct
74 Correct 20 ms 14008 KB Output is correct
75 Correct 21 ms 14012 KB Output is correct
76 Correct 20 ms 14012 KB Output is correct
77 Correct 21 ms 13900 KB Output is correct
78 Correct 19 ms 13948 KB Output is correct
79 Correct 19 ms 14004 KB Output is correct
80 Correct 20 ms 13900 KB Output is correct
81 Correct 20 ms 13900 KB Output is correct
82 Correct 26 ms 13900 KB Output is correct
83 Correct 21 ms 13900 KB Output is correct
84 Correct 20 ms 13900 KB Output is correct
85 Correct 23 ms 13928 KB Output is correct
86 Correct 19 ms 14012 KB Output is correct
87 Correct 27 ms 13900 KB Output is correct
88 Correct 20 ms 14008 KB Output is correct
89 Correct 20 ms 14008 KB Output is correct
90 Correct 19 ms 13900 KB Output is correct
91 Correct 21 ms 13900 KB Output is correct
92 Correct 19 ms 13900 KB Output is correct
93 Correct 19 ms 14012 KB Output is correct
94 Correct 20 ms 13900 KB Output is correct
95 Correct 20 ms 14008 KB Output is correct
96 Correct 20 ms 14016 KB Output is correct
97 Correct 20 ms 13900 KB Output is correct
98 Correct 20 ms 14012 KB Output is correct
99 Correct 20 ms 13900 KB Output is correct
100 Correct 20 ms 13900 KB Output is correct
101 Correct 19 ms 13888 KB Output is correct
102 Correct 26 ms 14008 KB Output is correct