intgetmin(std::string s){ int cnt2 = m / 4, k = 0; for (int i = 1; i <= m; ++i) a[i] = s[i] - '0'; int lst = 0; for (int i = 1; i <= m; ++i) { if (a[i]) ++lst; if (!a[i + 1] && lst) { b[++k] = lst, lst = 0; } } int sum = 0, tot = 0; for (int i = 1; i <= k; ++i) { sum += b[i] / 2; tot += b[i]; } if (sum <= cnt2) return sum + tot - 2 * sum; elsereturn cnt2 + tot - 2 * cnt2; }
intgetmax(std::string s){ int cnt2 = m / 4, k = 0, ret = 0; for (int i = 1; i <= m; ++i) { a[i] = s[i] - '0'; ret += a[i]; } for (int i = 1; i < m;) { if (!a[i] || !a[i + 1]) { ++k, i += 2; } else { ++i; } } return ret - (cnt2 - std::min(cnt2, k)); }
voiddickdreamer(){ int mi = 0, mx = 0; std::cin >> n >> m; for (int i = 1; i <= n; ++i) { std::string s; std::cin >> s; s = " " + s; mi += getmin(s), mx += getmax(s); } std::cout << mi << ' ' << mx << '\n'; }