Submission #683334

#TimeUsernameProblemLanguageResultExecution timeMemory
683334vjudge1Selotejp (COCI20_selotejp)C++17
110 / 110
65 ms44996 KiB
#pragma GCC optimize ("O3") #include <bits/stdc++.h> #define pii pair<int, int> #define piii pair<pii, int> #define vi vector<int> #define vvi vector<vi> #define vpii vector<pii> #define vvpii vector<vpii> #define f first #define s second #define oo 1000000001 #define eb emplace_back #define pb push_back #define mpr make_pair #define size(v) (int)v.size() #define ln '\n' #define ull unsigned long long #define ll long long #define all(v) v.begin(), v.end() using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve() { int n, m; cin >> n >> m; vector<string>cal(n); for (string &r : cal) { cin >> r; } vector<vvi>dp(n + 1, vvi(m + 1, vi(1 << m, oo))); for (int p = 0; p < (1 << m); ++p) { dp[0][0][p] = 0; } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { for (int p = 0; p < (1 << m); ++p) { if (cal[i][j] == '.') { dp[i][j + 1][p] = min(dp[i][j + 1][p], dp[i][j][p]); dp[i][j + 1][p ^ (1 << j)] = min(dp[i][j + 1][p ^ (1 << j)], dp[i][j][p]); } else { int h = (j && cal[i][j - 1] == '#' && (p & (1 << (j - 1)))) ? 0 : 1; int q = p | (1 << j); dp[i][j + 1][q] = min(dp[i][j + 1][q], dp[i][j][p] + h); int v = (i && cal[i - 1][j] == '#' && !(p & (1 << j))) ? 0 : 1; q ^= (1 << j); dp[i][j + 1][q] = min(dp[i][j + 1][q], dp[i][j][p] + v); } } } for (int p = 0; p < (1 << m); ++p) { dp[i + 1][0][p] = dp[i][m][p]; } } int res = oo; for (int p = 0; p < (1 << m); ++p) { res = min(res, dp[n][0][p]); } cout << res << ln; } int main() { ios_base::sync_with_stdio(false); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...