답안 #759061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759061 2023-06-15T17:45:09 Z boris_7 Dijamant (COCI22_dijamant) C++17
0 / 70
1 ms 468 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]=='.'){
                // cout<<-1<<endl;
                // a[i][j] = 1;
                // b[i][j] = 1;
                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][j]=1;
                // d[i][j]=1;
                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(pref[i][x2]-pref[i][x1]==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(pref[i][x2]-pref[i][x1]==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]){
                // cout<<i<<" "<<x1<<" "<<x2<<endl;
                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:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j = 0;j+1<e[i].size();j++){
      |                       ~~~^~~~~~~~~~~~
Main.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int j = 0;j+1<e[i].size();j++){
      |                       ~~~^~~~~~~~~~~~
Main.cpp:76:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int j = 0;j+1<e[i].size();j++){
      |                       ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 328 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 328 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -