Untitled
unknown
c_cpp
a year ago
2.9 kB
2
Indexable
Never
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <deque> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <array> #include <iomanip> using namespace std; using ll = long long; using ull = unsigned long long; using db = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<db, db>; using tiii = tuple<int, int, int>; using str = string; #define vt vector #define pb push_back #define eb emplace_back #define ins insert #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() #define mp make_pair #define mt make_tuple #define fi first #define se second void solve() { int n, m, x, y; cin >> n >> m >> x >> y; vt<vt<int>> a(n, vt<int> (m)); vt<int> sum_white(m), sum_black(m); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { char c; cin >> c; if (c == '.') { a[i][j] = 1; sum_white[j]++; } else { a[i][j] = 0; sum_black[j]++; } } } for (int i : sum_white) { cout << i << ' '; } cout << '\n'; for (int i : sum_black) { cout << i << ' '; } cout << '\n'; vt<int> pref_w(m + 1), pref_b(m + 1); pref_w[1] = sum_white[0]; pref_b[1] = sum_black[0]; for (int i = 2; i < n; ++i) { pref_w[i] = pref_w[i - 1] + sum_white[i - 1]; pref_b[i] = pref_b[i - 1] + sum_black[i - 1]; } vt<vt<int>> dp(2, vt<int> (m + 1)); dp[0][0] = 0; dp[1][0] = 0; for (int i = 0; i < 2; ++i) { for (int j = 1; j <= m; ++j) { int cur = INT_MAX; for (int e = x; e <= y; ++e) { int k = j - e; if (k < 0) k = 0; if (i == 0) { cur = min(cur, dp[1][k] + pref_w[j] - pref_w[k]); } if (i == 1) { cur = min(cur, dp[0][k] + pref_b[j] - pref_b[k]); } } dp[i][j] = cur; } } for (int i = 0; i < 2; ++i) { for (int j = 0; j <= m; ++j) { cout << dp[i][j] << ' '; } cout << endl; } cout << min(dp[0][m], dp[1][m]) << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); // freopen("data.in", "r", stdin); // freopen("data.out", "w", stdout); int tests = 1; // cin >> tests; while (tests--) { solve(); } return 0; }