#include <bits/stdc++.h>
using namespace std;
#define fod(i,a,b) for(int i = (int) (a); i <= (int) (b); i++)
#define fok(i,a,b) for(int i = (int) (a); i >= (int) (b); i--)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define el '\n'
#define ve vector
#define vi ve<int>
#define vll ve<ll>
#define mask(a) (1LL<<(a))
#define BIT(msk,i) (msk>>(i)&1LL)
using namespace std;
template <class T> bool mini(T &a, T b){ return (a > (b)) ? a = (b), 1 : 0; }
template <class T> bool maxi(T &a, T b){ return (a < (b)) ? a = (b), 1 : 0; }
#define name "selotejp"
int n, m;
char a[1005][15];
int dp[1005][15][mask(11)];
int off(int msk, int pos){
if(!BIT(msk, pos)) return msk;
return msk ^ mask(pos);
}
int on(int msk, int pos){
if(BIT(msk, pos)) return msk;
return msk ^ mask(pos);
}
int f(int i, int j, int msk, bool from_left){
if(i == n + 1) return 0;
if(j == m + 1) return f(i + 1, 1, msk, 0);
int &res = dp[i][j][msk];
if(~res) return res;
res = 1e9;
int up = BIT(msk, j);
if(a[i][j] == '.') return res = f(i,j+1,off(msk,j),0);
if(up) mini(res, f(i,j+1,msk,0));
else mini(res, f(i,j+1,on(msk,j),0) + 1);
if(from_left) mini(res, f(i,j+1,off(msk,j),1));
else mini(res, f(i,j+1,off(msk,j),1) + 1);
return res;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
fod(i,1,n) fod(j,1,m){
cin >> a[i][j];
}
memset(dp, -1, sizeof dp);
cout << f(1,1,0,0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
121168 KB |
Output is correct |
2 |
Correct |
61 ms |
121940 KB |
Output is correct |
3 |
Correct |
65 ms |
121800 KB |
Output is correct |
4 |
Correct |
62 ms |
122060 KB |
Output is correct |
5 |
Correct |
64 ms |
122192 KB |
Output is correct |
6 |
Correct |
65 ms |
122196 KB |
Output is correct |
7 |
Correct |
55 ms |
122192 KB |
Output is correct |
8 |
Correct |
51 ms |
121940 KB |
Output is correct |
9 |
Correct |
54 ms |
121940 KB |
Output is correct |
10 |
Correct |
70 ms |
122092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
121168 KB |
Output is correct |
2 |
Correct |
50 ms |
121056 KB |
Output is correct |
3 |
Correct |
51 ms |
121180 KB |
Output is correct |
4 |
Correct |
51 ms |
121172 KB |
Output is correct |
5 |
Correct |
63 ms |
121168 KB |
Output is correct |
6 |
Correct |
50 ms |
121132 KB |
Output is correct |
7 |
Correct |
50 ms |
121176 KB |
Output is correct |
8 |
Correct |
50 ms |
121172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
121168 KB |
Output is correct |
2 |
Correct |
61 ms |
121940 KB |
Output is correct |
3 |
Correct |
65 ms |
121800 KB |
Output is correct |
4 |
Correct |
62 ms |
122060 KB |
Output is correct |
5 |
Correct |
64 ms |
122192 KB |
Output is correct |
6 |
Correct |
65 ms |
122196 KB |
Output is correct |
7 |
Correct |
55 ms |
122192 KB |
Output is correct |
8 |
Correct |
51 ms |
121940 KB |
Output is correct |
9 |
Correct |
54 ms |
121940 KB |
Output is correct |
10 |
Correct |
70 ms |
122092 KB |
Output is correct |
11 |
Correct |
50 ms |
121168 KB |
Output is correct |
12 |
Correct |
50 ms |
121056 KB |
Output is correct |
13 |
Correct |
51 ms |
121180 KB |
Output is correct |
14 |
Correct |
51 ms |
121172 KB |
Output is correct |
15 |
Correct |
63 ms |
121168 KB |
Output is correct |
16 |
Correct |
50 ms |
121132 KB |
Output is correct |
17 |
Correct |
50 ms |
121176 KB |
Output is correct |
18 |
Correct |
50 ms |
121172 KB |
Output is correct |
19 |
Correct |
51 ms |
121596 KB |
Output is correct |
20 |
Correct |
54 ms |
121796 KB |
Output is correct |
21 |
Correct |
56 ms |
122036 KB |
Output is correct |
22 |
Correct |
60 ms |
122192 KB |
Output is correct |
23 |
Correct |
61 ms |
122148 KB |
Output is correct |
24 |
Correct |
62 ms |
121940 KB |
Output is correct |
25 |
Correct |
70 ms |
122196 KB |
Output is correct |
26 |
Correct |
96 ms |
122136 KB |
Output is correct |
27 |
Correct |
131 ms |
122176 KB |
Output is correct |
28 |
Correct |
192 ms |
122304 KB |
Output is correct |