Submission #1097888

# Submission time Handle Problem Language Result Execution time Memory
1097888 2024-10-08T14:20:46 Z 0pt1mus23 Selotejp (COCI20_selotejp) C++14
110 / 110
18 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ins insert      
#define pb push_back

#define endl '\n'
#define putr(x) cout<<x<<endl;return; 
#define all(x) x.begin(),x.end()
#define _ << " " <<
mt19937 rng(time(0));

const int mod = 998244353,
        sze = 1e3 +23,
        inf = 1e9,    
        L = 10;
void _0x0(){
    int n,m;
    cin>>n>>m;
    vector<int> last(1<<m,inf),curr(1<<m,0);
    last[0]=0;
    vector<char> arr[n];
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(auto v:s){
            arr[i].pb(v);
        }
    }

    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(arr[i][j]=='.'){
                        curr[mask]=inf;
                    }
                    else{
                        curr[mask]=min(last[mask], last[mask ^ (1<<j)] +1);
                    }
                }
                else{
                    curr[mask]=min(last[mask], last[mask ^ (1<<j)]);
                    if(arr[i][j]=='#' && (j ==0 || ( arr[i][j-1]=='.' || (mask & (1<<(j-1)))) ) ){
                        curr[mask]++;
                    }
                }
            }
            last=curr;
        }
    }

    putr(*min_element( all(last) ));

}
 
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int tt = 1;
    // cin>>tt;
    while(tt--){
        _0x0();
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 14 ms 344 KB Output is correct
6 Correct 18 ms 348 KB Output is correct
7 Correct 15 ms 348 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 13 ms 348 KB Output is correct
10 Correct 15 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 14 ms 344 KB Output is correct
6 Correct 18 ms 348 KB Output is correct
7 Correct 15 ms 348 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 13 ms 348 KB Output is correct
10 Correct 15 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 7 ms 524 KB Output is correct
22 Correct 12 ms 348 KB Output is correct
23 Correct 14 ms 348 KB Output is correct
24 Correct 13 ms 532 KB Output is correct
25 Correct 14 ms 348 KB Output is correct
26 Correct 15 ms 348 KB Output is correct
27 Correct 15 ms 536 KB Output is correct
28 Correct 16 ms 344 KB Output is correct