1 solutions

  • 0
    @ 2026-11-16 10:53:44

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int a[105][105];
    int n,m;
    int check(int x,int y){
            int mn=1000000;
            for(int i=x-1;i<=x+1;i++){
                    for(int j=y-1;j<=y+1;j++){
                            if(i<1||i>n||j<1||j>m) continue;
                            mn=min(a[i][j],mn);
    //                        cout << a[i][j] << " ";
                    }
            }
            if(mn==a[x][y]){
                    return true;
            }
            else{
                    return false;
            }
    }
    int main(){
            cin>>n>>m;
            for(int i=1;i<=n;i++){
                    for(int j=1;j<=m;j++){
                            cin>>a[i][j];
                    }
            }
            int ans=0;
            //check(1,2);
            for(int i=1;i<=n;i++){
                    for(int j=1;j<=m;j++){
                            if(check(i,j)){
              //              	cout << i << " " << j << endl;
                                    ans++;
                            }
                    }
            }
            cout<<ans<<endl;
      return 0;
    }
    
    • 1

    Information

    ID
    231
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By