Submission #337872

#TimeUsernameProblemLanguageResultExecution timeMemory
337872boykutBomb (IZhO17_bomb)C++14
3 / 100
381 ms6900 KiB
    #include <bits/stdc++.h>
     
    using namespace std;
     
    const int MAXN = 2501;
     
    //int dp[MAXN][MAXN];
    char a[MAXN][MAXN];
    //int sum[MAXN][MAXN];
     
    signed main() {
       int n, m;
       cin >> n >> m;
       for (int i = 1; i <= n; i++) {
          for (int j = 1; j <= m; j++) {
             cin >> a[i][j];
             //sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+int(a[i][j] == '1');
          }
       }
       //for (int i = 1; i <= n; i++) {
       //   for (int j = 1; j <= n; j++) {
       //      for (int a = 1; a <= i; a++) {
       //         for (int b = 1; b <= j; b++) {
       //            if (get(a, b, i, j))
       //               dp[i - a + 1][j - b + 1] = 1;
       //         }
       //      }
       //   }
       //}
       if (n == 1) {
          int ans = 2e9;
          for (int l = 1; l <= m;) {
             int r = l, cnt = 0;
             while (r <= m && a[1][r] == '1') cnt++, r++;
             if (cnt)
                ans = min(ans, cnt);
             l = r + 1;
          }
          cout << ans << '\n';
       } else if (m == 1) {
          int ans = 2e9;
          for (int l = 1; l <= n; l++) {
             int r = l, cnt = 0;
             while (r <= n && a[r][1] == '1') cnt++, r++;
             if (cnt)
                ans = min(ans, cnt);
          }
          cout << ans << '\n';
       }
       return 0;
    }
#Verdict Execution timeMemoryGrader output
Fetching results...