Submission #759072

# Submission time Handle Problem Language Result Execution time Memory
759072 2023-06-15T18:07:21 Z boris_7 Dijamant (COCI22_dijamant) C++17
70 / 70
100 ms 38476 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
int n,m;

bool check(int i,int j){
    return (i>=0 && j>=0 && i<n && j<m);
}

void solve(){
    cin>>n>>m;
    vector<string>v(n);
    for(int i = 0;i<n;i++){
        cin>>v[i];
    }
    vector<vector<int>>pref(n,vector<int>(m));
    vector<vector<int>>e(n);
    for(int i = 0;i<n;i++){
        if(v[i][0]=='#'){
            pref[i][0]=1;
            e[i].push_back(0);
        }
    }
    for(int i =0;i<n;i++){
        for(int j = 1;j<m;j++){
            pref[i][j]=pref[i][j-1]+(v[i][j]=='#');
            if(v[i][j]=='#') e[i].push_back(j);
        }
    }
    vector<vector<bool>>a,b,c,d;
    a = b = c = d = vector<vector<bool>>(n,vector<bool>(m));
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            if(check(i+1,j-1) && check(i+1,j+1) && v[i][j]=='#' && v[i+1][j-1] == '#' && v[i+1][j+1] == '#' && v[i+1][j]=='.'){
                a[i + 1][j - 1] = 1;
                b[i + 1][j + 1] = 1;
            }
            if(check(i-1,j-1) && check(i-1,j+1) && v[i][j]=='#' && v[i-1][j-1] == '#' && v[i-1][j+1] == '#' && v[i-1][j]=='.'){
                c[i-1][j-1]=1;
                d[i-1][j+1]=1;
            }
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j+1<e[i].size();j++){
            int x1 = e[i][j];
            int x2 = e[i][j+1];
            if(check(i-1,x1+1) && check(i-1,x2-1) && pref[i-1][x2-1]-pref[i-1][x1+1]==1){
                if(check(i-1,x1+1) && check(i-1,x2-1) && a[i-1][x1+1] && b[i-1][x2-1]){
                    a[i][x1]=1;
                    b[i][x2]=1;
                }
            }
        }
    }
    for(int i = n-1;i>=0;i--){
        for(int j = 0;j+1<e[i].size();j++){
            int x1 = e[i][j];
            int x2 = e[i][j+1];
            if(check(i+1,x1+1) && check(i+1,x2-1) && pref[i+1][x2-1]-pref[i+1][x1+1]==1){
                if(check(i+1,x1+1) && check(i+1,x2-1) && c[i+1][x1+1] && d[i+1][x2-1]){
                    c[i][x1]=1;
                    d[i][x2]=1;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1;i+1<n;i++){
        for(int j = 0;j+1<e[i].size();j++){
            int x1 = e[i][j];
            int x2 = e[i][j+1];
            if(a[i][x1] && c[i][x1] && b[i][x2] && d[i][x2]){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int j = 0;j+1<e[i].size();j++){
      |                       ~~~^~~~~~~~~~~~
Main.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int j = 0;j+1<e[i].size();j++){
      |                       ~~~^~~~~~~~~~~~
Main.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j = 0;j+1<e[i].size();j++){
      |                       ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 400 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 400 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 33 ms 20896 KB Output is correct
15 Correct 54 ms 36672 KB Output is correct
16 Correct 100 ms 27352 KB Output is correct
17 Correct 39 ms 21588 KB Output is correct
18 Correct 87 ms 38476 KB Output is correct
19 Correct 28 ms 19196 KB Output is correct
20 Correct 33 ms 22628 KB Output is correct
21 Correct 29 ms 19156 KB Output is correct
22 Correct 60 ms 24220 KB Output is correct
23 Correct 51 ms 22056 KB Output is correct
24 Correct 61 ms 24480 KB Output is correct
25 Correct 26 ms 18932 KB Output is correct
26 Correct 54 ms 27024 KB Output is correct