Submission #379078

#TimeUsernameProblemLanguageResultExecution timeMemory
379078topovikSelotejp (COCI20_selotejp)C++14
35 / 110
1097 ms772 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") #define F first #define S second #define pb push_back #define M ll(1e9 + 7) #define sz(x) (ll)x.size() #define re return #define oo ll(1e18) #define el '\n' #define pii pair <ll, ll> #define all(x) (x).begin(), (x).end() #define arr_all(x, n) (x + 1), (x + 1 + n) #define vi vector<ll> #define L 0 #define R 1 #define D 2 #define U 3 using namespace std; //using namespace __gnu_pbds; //typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int N = 1e3 + 500; int dp[N][N]; int n, m; int Calc(int *a) { int sum = 0; if (a[0] == 1) sum++; for (int i = 1; i < m; i++) if (a[i] == 1) sum += a[i] != a[i - 1]; return sum; } int main() { cin >> n >> m; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < (1 << m); i++) { int c[m]; for (int j = 0; j < m; j++) c[j] = (i >> j) & 1; for (int j = 0; j < m; j++) if (s[0][j] == '.') c[j] = 2; dp[0][i] = Calc(c); for (int j = 0; j < m; j++) dp[0][i] += (c[j] == 0); } for (int i = 1; i < n; i++) for (int msk = 0; msk < (1 << m); msk++) { int c[m]; for (int j = 0; j < m; j++) c[j] = (msk >> j) & 1; for (int j = 0; j < m; j++) if (s[i][j] == '.') c[j] = 2; dp[i][msk] = Calc(c); int mx = M; for (int msk1 = 0; msk1 < (1 << m); msk1++) { int c1[m]; for (int j = 0; j < m; j++) c1[j] = (msk1 >> j) & 1; for (int j = 0; j < m; j++) if (s[i - 1][j] == '.') c1[j] = 2; int val = dp[i - 1][msk1]; for (int j = 0; j < m; j++) val += (c[j] == 0 && c1[j] != c[j]); mx = min(mx, val); } dp[i][msk] += mx; } int ans = M; for (int msk = 0; msk < (1 << m); msk++) ans = min(ans, dp[n - 1][msk]); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...