# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
483173 | hollwo_pelw | Lamps (JOI19_lamps) | C++17 | 27 ms | 14016 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
// 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |