Codeforces Round #815 (Div. 2) 1720C. Corners Solution


 

 Problem Link:  https://codeforces.com/problemset/problem/1720/C

Solution in C++:

/// La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

/// Abul Hasnat  Tonmoy

/// Department of CSE,23rd batch

/// Islamic University,Bangladesh

///**********ALLAH IS ALMIGHTY************///

#include <bits/stdc++.h>

using namespace std;

char a[509][509];

int main() {

  ios_base::sync_with_stdio(0);

  cin.tie(0);

  int n, m, t;

  cin >> t;

  while (t--) {

    cin >> n >> m;

    int one = 0;

    for (int i = 1; i <= n; i++) {

      for (int j = 1; j <= m; j++) {

        cin >> a[i][j];

        if (a[i][j] == '1') one++;

      }

    }

    int mx = 0, c;

    for (int i = 1; i < n; i++) {

      for (int j = 1; j < m; j++) {

        c = 0;

        if (a[i][j] == '0') c++;

        if (a[i][j + 1] == '0') c++;

        if (a[i + 1][j] == '0') c++;

        if (a[i + 1][j + 1] == '0') c++;

        mx = max(mx, c);

      }

    }

    if (mx == 1)

      cout << one - 1 << endl;

    else if (mx >= 2)

      cout << one << endl;

    else

      cout << one - 2 << endl;

  }

  return 0;

}



No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.