From 445c7a15750a6a2187f9b3ef0086aacffde644e4 Mon Sep 17 00:00:00 2001 From: rlapo213 Date: Wed, 3 Aug 2022 22:38:51 +0900 Subject: [PATCH] Greedy,, --- .../2138.cpp" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "sources/rlapo213_\352\271\200\354\236\254\355\230\204/2138.cpp" diff --git "a/sources/rlapo213_\352\271\200\354\236\254\355\230\204/2138.cpp" "b/sources/rlapo213_\352\271\200\354\236\254\355\230\204/2138.cpp" new file mode 100644 index 0000000..5a5804e --- /dev/null +++ "b/sources/rlapo213_\352\271\200\354\236\254\355\230\204/2138.cpp" @@ -0,0 +1,60 @@ +#include +using namespace std; +int n, cnt; +bool a[100004]; +bool b[100004]; +bool c[100004]; + +bool s() { + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) + return false; + } + return true; +} + +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + scanf("%1d", &c[i]); + } + for (int i = 0; i < n; i++) { + scanf("%1d", &b[i]); + } + //±×³É ¾î·Æ°Ô »ý°¢ÇÏÁö¸»°í + //¸Ç¾Õ ¸ÇµÚ 2°³´Â bitmask·Î µ¹¸®°í ½ºÀ§Ä¡¸¦ i ´©¸£¸é i+1, i+2 ¹Ù²ï´Ù°í »ý°¢Çϸé + //ÇÑ Ä­ ³Ñ¾î°¡¸é ¹Ù²Ü ¼ö ¾øÀ¸´Ï±î ´Ù¸£¸é ¹Ù²Ù´Â ½ÄÀ¸·Î + + for (int u = 0; u < (1 << 2); u++) { + for (int i = 0; i < n; i++) + a[i] = c[i]; + cnt = 0; + if (u & (1 << 0)) { + a[0] = !a[0]; + a[1] = !a[1]; + cnt++; + } + if (u & (1 << 1)) { + a[n - 1] = !a[n - 1]; + a[n - 2] = !a[n - 2]; + cnt++; + } + for (int i = 0; i < n - 2; i++) { + if (a[i] != b[i]) { + a[i] = !a[i]; + a[i + 1] = !a[i + 1]; + a[i + 2] = !a[i + 2]; + cnt++; + } + } + + if (s()) { + cout << cnt; + return 0; + } + + } + + cout << -1; + return 0; +} \ No newline at end of file