# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1210572 | btninh | Selotejp (COCI20_selotejp) | C++20 | 0 ms | 324 KiB |
#include <bits/stdc++.h>
using namespace std;
#define btninh signed main
#define int long long
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define IO(x) if(fopen(x".inp","r")){freopen(x".inp","r",stdin);freopen(x".out","w",stdout);}
template<class Typ> bool mini(Typ &x, Typ y){if (x > y) return x = y, true; return false;}
const int N = 1005;
const int inf = 1e18;
int n, m, dp[2][1 << 11];
char a[N][15];
btninh(){
fast;
IO("main");
cin >> n >> m;
FOR(i, 1, n) FOR(j, 1, m) cin >> a[i][j];
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
int cur = 1, lst = 0;
FOR(i, 1, n){
FOR(j, 1, m){
FOR(msk, 0, (1 << m) - 1){
int bit = 1 << (j - 1);
int val = dp[lst][msk];
if (a[i][j] == '.'){
mini(dp[cur][msk & ~bit], val); // clear đoạn dọc
} else {
// Dán dọc
if (msk & bit){
mini(dp[cur][msk], val); // tiếp tục dán dọc
} else {
mini(dp[cur][msk | bit], val + 1); // bắt đầu dán dọc mới
}
// Dán ngang
if (j == 1 || a[i][j - 1] == '.' || !(msk & (1 << (j - 2)))){
// bắt đầu dán ngang mới
mini(dp[cur][msk], val + 1);
} else {
// tiếp tục dán ngang
mini(dp[cur][msk], val);
}
}
}
FOR(msk, 0, (1 << m) - 1) dp[lst][msk] = inf;
swap(cur, lst);
}
}
int ans = inf;
FOR(msk, 0, (1 << m) - 1) mini(ans, dp[lst][msk]);
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |