Submission #541400

# Submission time Handle Problem Language Result Execution time Memory
541400 2022-03-23T13:20:03 Z nigus Bomb (IZhO17_bomb) C++14
29 / 100
1000 ms 56296 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);

ll random2(){
    return (1ll << 31ll)*eng()+eng();
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 2501;

bool grid[MAXN][MAXN] = {0};

bool covered[MAXN][MAXN] = {0};

bool can_place(int i, int j, int a, int b){
    if(n-i < a || m-j < b)return 0;
    rep(c1,0,a){
        rep(c2,0,b){
            if(!grid[i+c1][j+c2])return 0;
        }
    }
    return 1;
}

bool can_cover(int i, int j, int a, int b){
    rep(dx,0,a){
        rep(dy,0,b){
            int i2 = i - dx;
            int j2 = j - dy;
            if(i2 >= 0 && j2 >= 0 && can_place(i2,j2,a,b))return 1;
        }
    }
    return 0;
}

bool solve(int a, int b){
    rep(c1,0,n){
        rep(c2,0,m){
            if(grid[c1][c2] && (c1 == n-1 || !grid[c1+1][c2] || c1 == 0 || !grid[c1-1][c2]) && !can_cover(c1,c2,a,b))return 0;
        }
    }
    return 1;
}

int lft[MAXN][MAXN] = {0};
int up[MAXN][MAXN] = {0};

int mina = big;
int minb = big;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

   // freopen("fhc.txt","r",stdin);
   // freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n >> m;
    rep(c1,0,n){
        string s;
        cin >> s;
        rep(c2,0,m){
            grid[c1][c2] = (s[c2] == '1');
        }
    }

    rep(c1,0,n){
        rep(c2,0,m){
            if(grid[c1][c2]){
                if(c1 == 0){
                    up[c1][c2] = 1;
                }
                else{
                    up[c1][c2] = up[c1-1][c2]+1;
                }

                if(c1 == n-1 || !grid[c1+1][c2])mina = min(mina, up[c1][c2]);

                if(c2 == 0){
                    lft[c1][c2] = 1;
                }
                else{
                    lft[c1][c2] = lft[c1][c2-1]+1;
                }

                if(c2 == m-1 || !grid[c1][c2+1])minb = min(minb, lft[c1][c2]);
            }
        }
    }

    ll ans = 0;

    rep(a,1,mina+1){
        rep(b,1,m+1){
            if(solve(a, b)){
                ans = max(ans, (ll)a*b);
            }
        }
    }
    cout << ans << "\n";


    return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:79:8: warning: unused variable 'a' [-Wunused-variable]
   79 |     ll a,b,c,d,e;
      |        ^
bomb.cpp:79:10: warning: unused variable 'b' [-Wunused-variable]
   79 |     ll a,b,c,d,e;
      |          ^
bomb.cpp:79:12: warning: unused variable 'c' [-Wunused-variable]
   79 |     ll a,b,c,d,e;
      |            ^
bomb.cpp:79:14: warning: unused variable 'd' [-Wunused-variable]
   79 |     ll a,b,c,d,e;
      |              ^
bomb.cpp:79:16: warning: unused variable 'e' [-Wunused-variable]
   79 |     ll a,b,c,d,e;
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 11 ms 26428 KB Output is correct
4 Correct 12 ms 26444 KB Output is correct
5 Correct 3 ms 328 KB Output is correct
6 Correct 19 ms 356 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 456 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 5 ms 980 KB Output is correct
20 Correct 5 ms 976 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 90 ms 980 KB Output is correct
24 Correct 6 ms 980 KB Output is correct
25 Correct 107 ms 1236 KB Output is correct
26 Incorrect 128 ms 1364 KB Output isn't correct
27 Incorrect 25 ms 4136 KB Output isn't correct
28 Correct 6 ms 1568 KB Output is correct
29 Execution timed out 1079 ms 5204 KB Time limit exceeded
30 Execution timed out 1077 ms 4308 KB Time limit exceeded
31 Execution timed out 1076 ms 3156 KB Time limit exceeded
32 Execution timed out 1078 ms 4180 KB Time limit exceeded
33 Execution timed out 1080 ms 5332 KB Time limit exceeded
34 Correct 8 ms 1820 KB Output is correct
35 Execution timed out 1072 ms 2136 KB Time limit exceeded
36 Execution timed out 1077 ms 6744 KB Time limit exceeded
37 Correct 1 ms 468 KB Output is correct
38 Execution timed out 1047 ms 56140 KB Time limit exceeded
39 Correct 1 ms 468 KB Output is correct
40 Execution timed out 1078 ms 15828 KB Time limit exceeded
41 Correct 1 ms 468 KB Output is correct
42 Execution timed out 1086 ms 1364 KB Time limit exceeded
43 Execution timed out 1018 ms 52300 KB Time limit exceeded
44 Execution timed out 1087 ms 6228 KB Time limit exceeded
45 Execution timed out 1062 ms 53580 KB Time limit exceeded
46 Execution timed out 1047 ms 56152 KB Time limit exceeded
47 Execution timed out 1061 ms 53656 KB Time limit exceeded
48 Execution timed out 1056 ms 56140 KB Time limit exceeded
49 Execution timed out 1089 ms 56236 KB Time limit exceeded
50 Execution timed out 1050 ms 56188 KB Time limit exceeded
51 Execution timed out 1053 ms 56140 KB Time limit exceeded
52 Execution timed out 1064 ms 56028 KB Time limit exceeded
53 Execution timed out 1040 ms 55548 KB Time limit exceeded
54 Execution timed out 1024 ms 42956 KB Time limit exceeded
55 Execution timed out 1050 ms 41152 KB Time limit exceeded
56 Execution timed out 1018 ms 56296 KB Time limit exceeded
57 Execution timed out 1066 ms 36300 KB Time limit exceeded
58 Execution timed out 1068 ms 41296 KB Time limit exceeded
59 Execution timed out 1073 ms 38244 KB Time limit exceeded
60 Execution timed out 1059 ms 47948 KB Time limit exceeded
61 Execution timed out 1067 ms 56140 KB Time limit exceeded
62 Execution timed out 1041 ms 56140 KB Time limit exceeded
63 Execution timed out 1059 ms 56140 KB Time limit exceeded
64 Execution timed out 1072 ms 38960 KB Time limit exceeded
65 Execution timed out 1065 ms 55076 KB Time limit exceeded
66 Execution timed out 1058 ms 52076 KB Time limit exceeded
67 Execution timed out 1069 ms 55980 KB Time limit exceeded
68 Execution timed out 1075 ms 55756 KB Time limit exceeded
69 Execution timed out 1063 ms 35440 KB Time limit exceeded
70 Execution timed out 1071 ms 15612 KB Time limit exceeded
71 Execution timed out 1066 ms 28456 KB Time limit exceeded
72 Execution timed out 1079 ms 33868 KB Time limit exceeded
73 Execution timed out 1071 ms 34544 KB Time limit exceeded
74 Execution timed out 1073 ms 36012 KB Time limit exceeded
75 Execution timed out 1078 ms 37584 KB Time limit exceeded
76 Execution timed out 1057 ms 38940 KB Time limit exceeded
77 Execution timed out 1070 ms 39372 KB Time limit exceeded
78 Execution timed out 1054 ms 39628 KB Time limit exceeded
79 Execution timed out 1026 ms 12108 KB Time limit exceeded
80 Execution timed out 1080 ms 13388 KB Time limit exceeded
81 Execution timed out 1052 ms 13772 KB Time limit exceeded
82 Execution timed out 1051 ms 42172 KB Time limit exceeded
83 Execution timed out 1058 ms 42284 KB Time limit exceeded
84 Execution timed out 1047 ms 7416 KB Time limit exceeded
85 Execution timed out 1048 ms 41288 KB Time limit exceeded
86 Execution timed out 1046 ms 54684 KB Time limit exceeded
87 Execution timed out 1041 ms 40116 KB Time limit exceeded
88 Execution timed out 1056 ms 40932 KB Time limit exceeded
89 Execution timed out 1043 ms 49628 KB Time limit exceeded
90 Execution timed out 1100 ms 29396 KB Time limit exceeded
91 Execution timed out 1082 ms 44620 KB Time limit exceeded
92 Execution timed out 1088 ms 46256 KB Time limit exceeded
93 Execution timed out 1088 ms 53336 KB Time limit exceeded
94 Execution timed out 1085 ms 48076 KB Time limit exceeded
95 Execution timed out 1043 ms 41928 KB Time limit exceeded
96 Execution timed out 1087 ms 41676 KB Time limit exceeded
97 Execution timed out 1078 ms 54256 KB Time limit exceeded
98 Execution timed out 1077 ms 41436 KB Time limit exceeded
99 Execution timed out 1089 ms 47640 KB Time limit exceeded
100 Execution timed out 1064 ms 52940 KB Time limit exceeded