Submission #379859

#TimeUsernameProblemLanguageResultExecution timeMemory
379859nguyen31hoang08minh2003Selotejp (COCI20_selotejp)C++14
110 / 110
237 ms98796 KiB
#include <bits/stdc++.h> #define fore(i, a, b) for (ll i = (a), _b = (b); i < _b; ++i) #define fort(i, a, b) for (ll i = (a), _b = (b); i <= _b; ++i) #define ford(i, a, b) for (ll i = (a), _b = (b); i >= _b; --i) #define fi first #define se second #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define getbit(x, i) ((x) & (1 << (i))) #define off(x, i) ((x) & (~(1 << (i)))) #define on(x, i) ((x) | (1 << (i))) using namespace std; template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;}; template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;}; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; const int maxN = 1000, maxM = 10, inf = 1e9; int n, m, dp[maxN][maxM][1 << maxM][2]; bool vis[maxN][maxM][1 << maxM][2]; char s[maxN][maxM]; int DP(const int r, const int c, const int vertical, const bool horizontal) { if (r >= n) return 0; if (!vis[r][c][vertical][horizontal]) { vis[r][c][vertical][horizontal] = true; dp[r][c][vertical][horizontal] = inf; if (c + 1 < m) { if (s[r][c] == '.') mini(dp[r][c][vertical][horizontal], DP(r, c + 1, off(vertical, c), false)); else { if (getbit(vertical, c)) mini(dp[r][c][vertical][horizontal], DP(r, c + 1, vertical, false)); else mini(dp[r][c][vertical][horizontal], DP(r, c + 1, on(vertical, c), false) + 1); mini(dp[r][c][vertical][horizontal], DP(r, c + 1, off(vertical, c), true) + !horizontal); } } else { if (s[r][c] == '.') mini(dp[r][c][vertical][horizontal], DP(r + 1, 0, off(vertical, c), false)); else { if (getbit(vertical, c)) mini(dp[r][c][vertical][horizontal], DP(r + 1, 0, vertical, false)); else mini(dp[r][c][vertical][horizontal], DP(r + 1, 0, on(vertical, c), false) + 1); mini(dp[r][c][vertical][horizontal], DP(r + 1, 0, off(vertical, c), false) + !horizontal); } } } return dp[r][c][vertical][horizontal]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; fore(i, 0, n) cin >> s[i]; cout << DP(0, 0, 0, false) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...