Submission #368122

# Submission time Handle Problem Language Result Execution time Memory
368122 2021-02-19T15:25:10 Z egekabas Selotejp (COCI20_selotejp) C++14
110 / 110
200 ms 4460 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, m;
int a[1000][10];
int dp[1000][(1<<10)];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> m;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        for(int j = 0; j < m; ++j){
            a[i][j] = (s[j] == '#');
        }
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < (1<<m); ++j)
            dp[i][j] = 1e9;
    dp[0][0] = 0;
    int ans = 1e9;
    for(int i = 0; i < n; ++i)
        for(int bit = 0; bit < (1<<m); ++bit){
            int bad = 0;
            for(int j = 0; j < m; ++j)
                if( (bit&(1<<j)) && (a[i][j] == 0) )
                    bad = 1;
            if(bad){
                continue;
            }
            for(int j = 0; j < m; ++j)
                if((bit&(1<<j)) == 0)
                    dp[i][bit+(1<<j)] = min(dp[i][bit+(1<<j)], dp[i][bit]+1);
            
            for(int j = 0; j < m; ++j){
                if((bit&(1<<j)) || a[i][j] == 0) continue;
                if(j == 0 || (bit&(1<<(j-1))) || a[i][j-1] == 0)
                    ++dp[i][bit];
            }
            
            /*cout << i << ' ';
            for(int j = 0; j < m; ++j)
                cout << ((bit&(1<<j)) > 0);
            cout << '\n' << dp[i][bit] << '\n';*/
            
            if(i == n-1){
                ans = min(ans, dp[i][bit]);
            }
            else{
                for(int newbit = bit; ;newbit = (bit&(newbit-1))){
                    dp[i+1][newbit] = min(dp[i][bit], dp[i+1][newbit]);
                    if(!newbit) break;
                }
            }
        }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 48 ms 4076 KB Output is correct
3 Correct 11 ms 4076 KB Output is correct
4 Correct 27 ms 4204 KB Output is correct
5 Correct 57 ms 4332 KB Output is correct
6 Correct 53 ms 4332 KB Output is correct
7 Correct 50 ms 4204 KB Output is correct
8 Correct 47 ms 4076 KB Output is correct
9 Correct 48 ms 4204 KB Output is correct
10 Correct 134 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 48 ms 4076 KB Output is correct
3 Correct 11 ms 4076 KB Output is correct
4 Correct 27 ms 4204 KB Output is correct
5 Correct 57 ms 4332 KB Output is correct
6 Correct 53 ms 4332 KB Output is correct
7 Correct 50 ms 4204 KB Output is correct
8 Correct 47 ms 4076 KB Output is correct
9 Correct 48 ms 4204 KB Output is correct
10 Correct 134 ms 4332 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 3 ms 4204 KB Output is correct
20 Correct 15 ms 4332 KB Output is correct
21 Correct 30 ms 4460 KB Output is correct
22 Correct 51 ms 4204 KB Output is correct
23 Correct 49 ms 4204 KB Output is correct
24 Correct 52 ms 4204 KB Output is correct
25 Correct 56 ms 4332 KB Output is correct
26 Correct 86 ms 4332 KB Output is correct
27 Correct 136 ms 4204 KB Output is correct
28 Correct 200 ms 4460 KB Output is correct