Submission #333908

# Submission time Handle Problem Language Result Execution time Memory
333908 2020-12-08T02:50:56 Z talant117408 Bomb (IZhO17_bomb) C++17
24 / 100
596 ms 123756 KB
/*
    Code written by Talant I.D.
*/
  
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
  
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
  
inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
  
inline bool isprime(int n){
    if(n < 2 || (n%2 == 0 && n != 2)) return false;
    for(int i = 3; i*i <= n; i++)
        if(n%i == 0) return false;
    return true;
}
 
class Union{
    private:
        vector <int> saizu, link;
    public:
        Union(int n){
            saizu.assign(n, 1); link.resize(n); 
            iota(all(link), 0);
        }
        int find(int n){
            if(link[n] == n) return n;
            return link[n] = find(link[n]);
        }
        int same(int a, int b){
            return find(a) == find(b);
        }
        void unite(int a, int b){
            if(same(a, b)) return;
             
            a = find(a); b = find(b);
            if(saizu[a] < saizu[b]) swap(a, b);
             
            saizu[a] += saizu[b];
            link[b] = a;
        }
        int getsize(int a){
            return saizu[find(a)];
        }
};
 
const int mod = 1e9+7;
 
ll mode(ll a){
    a %= mod;
    if(a < 0) a += mod;
    return a;
}
 
ll subt(ll a, ll b){
    return mode(mode(a)-mode(b));
}
 
ll add(ll a, ll b){
    return mode(mode(a)+mode(b));
}
 
ll mult(ll a, ll b){
    return mode(mode(a)*mode(b));
}
 
ll binpow(ll a, ll b){
    ll res = 1;
    while(b){
        if(b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}
/*
struct Node{
    ll val, l, r, sum;
    Node operator + (Node other){
        return {max(max(val, other.val), r+other.l), max(l, sum+other.l), max(other.r, other.sum+r), sum+other.sum}; 
    }
};

class Segment_tree{
    private:
        vector <Node> tree;
        //vector <int> lz;
    public:
        Segment_tree(int n){
            tree.resize(n*4);
            //lz.resize(n*4);
        }
        void build(int v, int l, int r){
            if(l == r){
                tree[v] = {max(0ll, vec[l]), max(0ll, vec[l]), max(0ll, vec[l]), vec[l]};
                return;
            }
            int mid = (l+r) >> 1;
            build(v*2, l, mid);
            build(v*2+1, mid+1, r);
            tree[v] = tree[v*2] + tree[v*2+1];
        }
        void push(int v, int l, int r){
            if(lz[v]){
                tree[v] += (r-l+1)*lz[v];
                if(l != r){
                    lz[v*2] += lz[v];
                    lz[v*2+1] += lz[v];
                }
                lz[v] = 0;
            }
        }
        int get(int v, int l, int r, int val){
            if(l == r){
                return l;
            }
            int mid = (l+r) >> 1;
            if(tree[v*2] >= val) return get(v*2, l, mid, val);
            else return get(v*2+1, mid+1, r, val);
        }
        void update(int v, int l, int r, int pos, ll val){
            if(l == r && l == pos){
                tree[v] = {max(0ll, val), max(0ll, val), max(0ll, val), val};
                return ;
            }
            int mid = (l+r) >> 1;  
            if(pos <= mid) update(v*2, l, mid, pos, val);
            else update(v*2+1, mid+1, r, pos, val);
            tree[v] = tree[v*2] + tree[v*2+1];
        }
        ll get_first(){
            return tree[1].val;
        }
};*/

int main(){
    do_not_disturb
    
    int n, m;
    int i, j;
    cin >> n >> m;
    int grid[n+1][m+1];
    int pref[2][n+2][m+2], suff[2][n+2][m+2];
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            char ch;
            cin >> ch;
            grid[i][j] = int(ch-'0');
        }
    }
    
    for(i = 1; i <= n; i++){
        pref[0][i][0] = 0;
        suff[0][i][m+1] = m+1;
        for(j = 1; j <= m; j++){
            if(!grid[i][j]) pref[0][i][j] = j;
            else pref[0][i][j] = pref[0][i][j-1];
        }
        for(j = m; j; j--){
            if(!grid[i][j]) suff[0][i][j] = j;
            else suff[0][i][j] = suff[0][i][j+1];
        }
    }
    for(j = 1; j <= m; j++){
        pref[1][0][j] = 0;
        suff[1][n+1][j] = n+1;
        for(i = 1; i <= n; i++){
            if(!grid[i][j]) pref[1][i][j] = i;
            else pref[1][i][j] = pref[1][i-1][j];
        }
        for(i = n; i; i--){
            if(!grid[i][j]) suff[1][i][j] = i;
            else suff[1][i][j] = suff[1][i+1][j];
        }
    }
    
    ll mxx = 2000000000, mxy = 2000000000;
    
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            if(grid[i][j]){
                mxx = min(mxx, (ll)suff[0][i][j]-pref[0][i][j]-1);
            }
        }
    }
    
    for(i = 1; i <= m; i++){
        for(j = 1; j <= n; j++){
            if(grid[j][i]){
                mxy = min(mxy, (ll)suff[1][j][i]-pref[1][j][i]-1);
            }
        }
    }
    /*
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cout << pref[0][i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cout << suff[0][i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cout << pref[1][i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cout << suff[1][i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
    
    cout << mxx << ' ' << mxy << endl;*/
    
    cout << (mxx == 2e9 ? 0ll : mxx*mxy);
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Incorrect 1 ms 364 KB Output isn't correct
11 Incorrect 0 ms 364 KB Output isn't correct
12 Incorrect 0 ms 364 KB Output isn't correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Incorrect 1 ms 492 KB Output isn't correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Incorrect 1 ms 364 KB Output isn't correct
19 Incorrect 1 ms 492 KB Output isn't correct
20 Incorrect 1 ms 492 KB Output isn't correct
21 Incorrect 1 ms 364 KB Output isn't correct
22 Incorrect 1 ms 492 KB Output isn't correct
23 Incorrect 1 ms 492 KB Output isn't correct
24 Incorrect 1 ms 492 KB Output isn't correct
25 Incorrect 1 ms 492 KB Output isn't correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 4 ms 1900 KB Output is correct
28 Incorrect 4 ms 2540 KB Output isn't correct
29 Incorrect 6 ms 2796 KB Output isn't correct
30 Incorrect 7 ms 4076 KB Output isn't correct
31 Incorrect 6 ms 3308 KB Output isn't correct
32 Incorrect 6 ms 3436 KB Output isn't correct
33 Incorrect 8 ms 4332 KB Output isn't correct
34 Incorrect 40 ms 1900 KB Output isn't correct
35 Incorrect 8 ms 4460 KB Output isn't correct
36 Correct 9 ms 4332 KB Output is correct
37 Incorrect 1 ms 364 KB Output isn't correct
38 Correct 596 ms 123372 KB Output is correct
39 Incorrect 1 ms 364 KB Output isn't correct
40 Incorrect 63 ms 15468 KB Output isn't correct
41 Incorrect 1 ms 364 KB Output isn't correct
42 Incorrect 1 ms 492 KB Output isn't correct
43 Correct 548 ms 123500 KB Output is correct
44 Incorrect 9 ms 4332 KB Output isn't correct
45 Incorrect 546 ms 123372 KB Output isn't correct
46 Correct 518 ms 123372 KB Output is correct
47 Incorrect 535 ms 123244 KB Output isn't correct
48 Incorrect 530 ms 123244 KB Output isn't correct
49 Correct 578 ms 123244 KB Output is correct
50 Incorrect 534 ms 123244 KB Output isn't correct
51 Incorrect 531 ms 123392 KB Output isn't correct
52 Incorrect 530 ms 123244 KB Output isn't correct
53 Incorrect 524 ms 123244 KB Output isn't correct
54 Incorrect 515 ms 123208 KB Output isn't correct
55 Incorrect 494 ms 123368 KB Output isn't correct
56 Correct 571 ms 123244 KB Output is correct
57 Incorrect 490 ms 123372 KB Output isn't correct
58 Incorrect 485 ms 123244 KB Output isn't correct
59 Incorrect 478 ms 123244 KB Output isn't correct
60 Correct 515 ms 123244 KB Output is correct
61 Correct 572 ms 123244 KB Output is correct
62 Correct 579 ms 123244 KB Output is correct
63 Correct 595 ms 123244 KB Output is correct
64 Correct 487 ms 123244 KB Output is correct
65 Incorrect 515 ms 123244 KB Output isn't correct
66 Incorrect 526 ms 123372 KB Output isn't correct
67 Incorrect 532 ms 123244 KB Output isn't correct
68 Incorrect 535 ms 123244 KB Output isn't correct
69 Incorrect 494 ms 123372 KB Output isn't correct
70 Incorrect 290 ms 79340 KB Output isn't correct
71 Incorrect 470 ms 123372 KB Output isn't correct
72 Incorrect 485 ms 123300 KB Output isn't correct
73 Incorrect 486 ms 123372 KB Output isn't correct
74 Incorrect 479 ms 123372 KB Output isn't correct
75 Incorrect 482 ms 123244 KB Output isn't correct
76 Incorrect 486 ms 123500 KB Output isn't correct
77 Incorrect 496 ms 123244 KB Output isn't correct
78 Incorrect 487 ms 123500 KB Output isn't correct
79 Incorrect 452 ms 123372 KB Output isn't correct
80 Incorrect 444 ms 123500 KB Output isn't correct
81 Incorrect 453 ms 123500 KB Output isn't correct
82 Incorrect 490 ms 123372 KB Output isn't correct
83 Incorrect 492 ms 123372 KB Output isn't correct
84 Incorrect 449 ms 123372 KB Output isn't correct
85 Incorrect 483 ms 123244 KB Output isn't correct
86 Incorrect 561 ms 123500 KB Output isn't correct
87 Incorrect 485 ms 123372 KB Output isn't correct
88 Incorrect 487 ms 123372 KB Output isn't correct
89 Incorrect 510 ms 123500 KB Output isn't correct
90 Incorrect 301 ms 79340 KB Output isn't correct
91 Incorrect 495 ms 123244 KB Output isn't correct
92 Incorrect 514 ms 123756 KB Output isn't correct
93 Incorrect 560 ms 123244 KB Output isn't correct
94 Incorrect 510 ms 123244 KB Output isn't correct
95 Incorrect 490 ms 123348 KB Output isn't correct
96 Incorrect 493 ms 123500 KB Output isn't correct
97 Incorrect 573 ms 123244 KB Output isn't correct
98 Incorrect 499 ms 123228 KB Output isn't correct
99 Incorrect 507 ms 123452 KB Output isn't correct
100 Incorrect 565 ms 123244 KB Output isn't correct