이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second
const ll N = 1005;
const ll M = 10;
const ll INF = 1e9;
ll n,m;
char grid[N][M+2];
ll memo[N][M+2][(1 << M)+5][2];
ll dp(ll x, ll y, ll mask, ll stat) {
if(x == n+1) return 0;
ll temp = memo[x][y][mask][stat];
if(temp != -1) return temp;
temp = INF;
if(y == m+1) temp = dp(x+1,1,mask,0);
else {
if(mask >> (y-1) & 1) {
if(grid[x][y] == '.') {
temp = min(temp,dp(x,y+1,mask-(1 << (y-1)),0));
}
else {
temp = min({temp,dp(x,y+1,mask,0), dp(x,y+1,mask-(1 << (y-1)),1) + (stat^1)});
}
}
else {
if(grid[x][y] == '.') {
temp = min(temp,dp(x,y+1,mask,0));
}
else {
temp = min({temp,dp(x,y+1,mask + (1 << (y-1)),0)+1, dp(x,y+1,mask,1)+(stat^1)});
}
}
}
memo[x][y][mask][stat] = temp;
return memo[x][y][mask][stat];
}
int main() {
memset(memo,-1,sizeof(memo));
cin >> n >> m;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
cin >> grid[i][j];
}
}
cout << dp(1,1,0,0) << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |