Submission #1024041

# Submission time Handle Problem Language Result Execution time Memory
1024041 2024-07-15T10:45:21 Z kustizus Selotejp (COCI20_selotejp) C++17
110 / 110
37 ms 40792 KB
#include <bits/stdc++.h>
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // freopen ("file.inp","r",stdin);
    // freopen ("file.out","w",stdout);
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    vector<vector<vector<int>>> dp(n, vector<vector<int>>(m, vector<int>(1 << m, 1e9)));
    for (string &x : s)
        cin >> x;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            for (int mask = 0; mask < (1 << m); mask++)
                if (mask & (1 << j))
                {
                    if (s[i][j] == '.')
                        dp[i][j][mask] = 1e9;
                    else if (!j)
                    {
                        if (!i)
                            dp[i][j][mask] = (mask != 1 ? 1e9 : 1);
                        else
                            dp[i][j][mask] = min(dp[i - 1][m - 1][mask], dp[i - 1][m - 1][mask ^ (1 << j)] + 1);
                    }
                    else
                        dp[i][j][mask] = min(dp[i][j - 1][mask], dp[i][j - 1][mask ^ (1 << j)] + 1);
                }
                else
                {
                    if (!j)
                    {
                        if (!i)
                            dp[i][j][mask] = (mask != 0 ? 1e9 : (s[i][j] == '#'));
                        else
                            dp[i][j][mask] = min(dp[i - 1][m - 1][mask], dp[i - 1][m - 1][mask ^ (1 << j)]) + (s[i][j] == '#');
                    }
                    else
                    {
                        dp[i][j][mask] = min(dp[i][j - 1][mask], dp[i][j - 1][mask ^ (1 << j)]);
                        if (s[i][j] == '#' && (!j || mask & (1 << (j - 1)) || s[i][j - 1] == '.'))
                            dp[i][j][mask]++;
                    }
                }
    int ans = 1e9;
    for (int i = 0; i < (1 << m); i++)
        ans = min(ans, dp[n - 1][m - 1][i]);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 33 ms 37724 KB Output is correct
3 Correct 7 ms 8028 KB Output is correct
4 Correct 21 ms 18268 KB Output is correct
5 Correct 35 ms 40284 KB Output is correct
6 Correct 35 ms 40284 KB Output is correct
7 Correct 34 ms 39256 KB Output is correct
8 Correct 31 ms 37724 KB Output is correct
9 Correct 32 ms 37976 KB Output is correct
10 Correct 35 ms 40792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 708 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 0 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 33 ms 37724 KB Output is correct
3 Correct 7 ms 8028 KB Output is correct
4 Correct 21 ms 18268 KB Output is correct
5 Correct 35 ms 40284 KB Output is correct
6 Correct 35 ms 40284 KB Output is correct
7 Correct 34 ms 39256 KB Output is correct
8 Correct 31 ms 37724 KB Output is correct
9 Correct 32 ms 37976 KB Output is correct
10 Correct 35 ms 40792 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 708 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 1112 KB Output is correct
20 Correct 8 ms 8536 KB Output is correct
21 Correct 15 ms 18780 KB Output is correct
22 Correct 31 ms 39516 KB Output is correct
23 Correct 32 ms 39260 KB Output is correct
24 Correct 32 ms 39260 KB Output is correct
25 Correct 35 ms 40028 KB Output is correct
26 Correct 34 ms 38572 KB Output is correct
27 Correct 35 ms 38488 KB Output is correct
28 Correct 37 ms 39768 KB Output is correct