#include <bits/stdc++.h>
using namespace std;
int n, m;
bool arr[1001][11];
vector <pair <int, int>> q;
bool check (int &x, int &y) {
return (x >> y) & 1;
}
bool vis[1 << 10][11][11][2];
void recurse (int pos, int mask, int newmask, int cur, int sum, bool c = 0) {
if (vis[newmask][cur][sum][c]) return;
vis[newmask][cur][sum][c] = 1;
if (cur == m) {
q.push_back({sum, newmask});
return;
}
if (arr[pos][cur] == 0) {
recurse(pos, mask, newmask, cur + 1, sum, 0);
return;
}
if (check(mask, cur)) {
recurse(pos, mask, newmask + (1 << cur), cur + 1, sum, 0);
} else {
recurse(pos, mask, newmask + (1 << cur), cur + 1, sum + 1, 0);
}
recurse(pos, mask, newmask, cur + 1, sum + (c ^ 1), 1);
}
string get2 (int x);
int dp[1001][1 << 10];
int ans (int pos, int mask) {
if (pos == 0) return 0;
int &ret = dp[pos][mask];
if (ret != -1) return ret;
memset(vis, 0, sizeof(vis));
recurse(pos, mask, 0, 0, 0);
int mn = 1e9;
vector <pair <int, int>> t = q; q.clear();
for (auto i : t) mn = min(mn, i.first + ans(pos - 1, i.second));
return ret = mn;
}
string get2 (int x) {
string s;
for (int i = 0; i < m; i++) s += (char)(check(x, i) + '0');
return s;
}
int main () {
memset(dp, -1, sizeof(dp));
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
char x; cin >> x; arr[i][j] = x == '#';
}
}
cout << ans(n, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4696 KB |
Output is correct |
2 |
Correct |
39 ms |
4700 KB |
Output is correct |
3 |
Correct |
40 ms |
4952 KB |
Output is correct |
4 |
Correct |
39 ms |
4700 KB |
Output is correct |
5 |
Correct |
57 ms |
4700 KB |
Output is correct |
6 |
Correct |
72 ms |
4960 KB |
Output is correct |
7 |
Correct |
67 ms |
4952 KB |
Output is correct |
8 |
Correct |
11 ms |
4696 KB |
Output is correct |
9 |
Correct |
35 ms |
4700 KB |
Output is correct |
10 |
Execution timed out |
1066 ms |
8796 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
14 ms |
4720 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
28 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
9 ms |
4700 KB |
Output is correct |
8 |
Correct |
9 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4696 KB |
Output is correct |
2 |
Correct |
39 ms |
4700 KB |
Output is correct |
3 |
Correct |
40 ms |
4952 KB |
Output is correct |
4 |
Correct |
39 ms |
4700 KB |
Output is correct |
5 |
Correct |
57 ms |
4700 KB |
Output is correct |
6 |
Correct |
72 ms |
4960 KB |
Output is correct |
7 |
Correct |
67 ms |
4952 KB |
Output is correct |
8 |
Correct |
11 ms |
4696 KB |
Output is correct |
9 |
Correct |
35 ms |
4700 KB |
Output is correct |
10 |
Execution timed out |
1066 ms |
8796 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |