Submission #58869

# Submission time Handle Problem Language Result Execution time Memory
58869 2018-07-19T16:57:14 Z Benq Bomb (IZhO17_bomb) C++14
41 / 100
1000 ms 132096 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 2505;

int cum1[MX][MX], cum2[MX][MX];
char gr[MX][MX];
int n,m;

bool ok(int x, int y) {
    FOR(i,1,n+1) FOR(j,1,m+1) cum2[i][j] = 0;
    F0R(i,n+1-x) F0R(j,m+1-y) if (cum1[i+x][j+y]-cum1[i][j+y]-cum1[i+x][j]+cum1[i][j] == x*y) {
        cum2[i+1][j+1] ++;
        cum2[i+1][j+1+y] --;
        cum2[i+1+x][j+1] --;
        cum2[i+1+x][j+1+y] ++;
    }
    FOR(i,1,n+1) FOR(j,1,m+1) {
        cum2[i][j] += cum2[i][j-1]+cum2[i-1][j]-cum2[i-1][j-1];
        if (gr[i][j] == '1' && !cum2[i][j]) return 0;
    }
    return 1;
}

int main() {
    // freopen("bomb.in","r",stdin);
    // freopen("bomb.out","w",stdout);
    cin >> n >> m;
    FOR(i,1,n+1) FOR(j,1,m+1) {
        cin >> gr[i][j];
        cum1[i][j] = cum1[i-1][j]+cum1[i][j-1]-cum1[i-1][j-1];
        if (gr[i][j] == '1') cum1[i][j] ++;
    }
    int x = 0, ans = 0;
    FORd(i,1,n+1) {
        while (ok(i,x+1)) x ++;
        ans = max(ans,i*x);
    }
    cout << ans;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 223 ms 26672 KB Output is correct
4 Correct 190 ms 26840 KB Output is correct
5 Correct 3 ms 26840 KB Output is correct
6 Correct 3 ms 26840 KB Output is correct
7 Correct 3 ms 26840 KB Output is correct
8 Correct 3 ms 26840 KB Output is correct
9 Correct 4 ms 26840 KB Output is correct
10 Correct 3 ms 26840 KB Output is correct
11 Correct 2 ms 26840 KB Output is correct
12 Correct 3 ms 26840 KB Output is correct
13 Correct 3 ms 26840 KB Output is correct
14 Correct 3 ms 26840 KB Output is correct
15 Correct 3 ms 26840 KB Output is correct
16 Correct 4 ms 26840 KB Output is correct
17 Correct 5 ms 26840 KB Output is correct
18 Correct 5 ms 26840 KB Output is correct
19 Correct 6 ms 26840 KB Output is correct
20 Correct 8 ms 26840 KB Output is correct
21 Correct 4 ms 26840 KB Output is correct
22 Correct 6 ms 26840 KB Output is correct
23 Correct 12 ms 26840 KB Output is correct
24 Correct 8 ms 26840 KB Output is correct
25 Correct 10 ms 26840 KB Output is correct
26 Correct 10 ms 26840 KB Output is correct
27 Correct 84 ms 26840 KB Output is correct
28 Correct 75 ms 26840 KB Output is correct
29 Correct 224 ms 26840 KB Output is correct
30 Correct 340 ms 26840 KB Output is correct
31 Correct 266 ms 26840 KB Output is correct
32 Correct 195 ms 26840 KB Output is correct
33 Correct 424 ms 26840 KB Output is correct
34 Correct 59 ms 26840 KB Output is correct
35 Correct 321 ms 26840 KB Output is correct
36 Correct 353 ms 26840 KB Output is correct
37 Correct 4 ms 26840 KB Output is correct
38 Execution timed out 1078 ms 63632 KB Time limit exceeded
39 Correct 4 ms 63632 KB Output is correct
40 Execution timed out 1076 ms 63632 KB Time limit exceeded
41 Correct 3 ms 63632 KB Output is correct
42 Correct 10 ms 63632 KB Output is correct
43 Execution timed out 1082 ms 70572 KB Time limit exceeded
44 Correct 500 ms 70572 KB Output is correct
45 Execution timed out 1076 ms 76948 KB Time limit exceeded
46 Execution timed out 1087 ms 82884 KB Time limit exceeded
47 Execution timed out 1084 ms 89152 KB Time limit exceeded
48 Execution timed out 1091 ms 95304 KB Time limit exceeded
49 Execution timed out 1087 ms 101448 KB Time limit exceeded
50 Execution timed out 1077 ms 107508 KB Time limit exceeded
51 Execution timed out 1092 ms 113624 KB Time limit exceeded
52 Execution timed out 1081 ms 119772 KB Time limit exceeded
53 Execution timed out 1086 ms 125816 KB Time limit exceeded
54 Execution timed out 1078 ms 131976 KB Time limit exceeded
55 Execution timed out 1085 ms 132096 KB Time limit exceeded
56 Execution timed out 1088 ms 132096 KB Time limit exceeded
57 Execution timed out 1083 ms 132096 KB Time limit exceeded
58 Execution timed out 1089 ms 132096 KB Time limit exceeded
59 Execution timed out 1085 ms 132096 KB Time limit exceeded
60 Execution timed out 1080 ms 132096 KB Time limit exceeded
61 Execution timed out 1064 ms 132096 KB Time limit exceeded
62 Execution timed out 1090 ms 132096 KB Time limit exceeded
63 Execution timed out 1085 ms 132096 KB Time limit exceeded
64 Execution timed out 1087 ms 132096 KB Time limit exceeded
65 Execution timed out 1067 ms 132096 KB Time limit exceeded
66 Execution timed out 1091 ms 132096 KB Time limit exceeded
67 Execution timed out 1078 ms 132096 KB Time limit exceeded
68 Execution timed out 1085 ms 132096 KB Time limit exceeded
69 Execution timed out 1086 ms 132096 KB Time limit exceeded
70 Execution timed out 1090 ms 132096 KB Time limit exceeded
71 Execution timed out 1075 ms 132096 KB Time limit exceeded
72 Execution timed out 1072 ms 132096 KB Time limit exceeded
73 Execution timed out 1080 ms 132096 KB Time limit exceeded
74 Execution timed out 1078 ms 132096 KB Time limit exceeded
75 Execution timed out 1084 ms 132096 KB Time limit exceeded
76 Execution timed out 1087 ms 132096 KB Time limit exceeded
77 Execution timed out 1063 ms 132096 KB Time limit exceeded
78 Execution timed out 1080 ms 132096 KB Time limit exceeded
79 Execution timed out 1078 ms 132096 KB Time limit exceeded
80 Execution timed out 1095 ms 132096 KB Time limit exceeded
81 Execution timed out 1084 ms 132096 KB Time limit exceeded
82 Execution timed out 1085 ms 132096 KB Time limit exceeded
83 Execution timed out 1094 ms 132096 KB Time limit exceeded
84 Execution timed out 1089 ms 132096 KB Time limit exceeded
85 Execution timed out 1088 ms 132096 KB Time limit exceeded
86 Execution timed out 1089 ms 132096 KB Time limit exceeded
87 Execution timed out 1082 ms 132096 KB Time limit exceeded
88 Execution timed out 1084 ms 132096 KB Time limit exceeded
89 Execution timed out 1092 ms 132096 KB Time limit exceeded
90 Execution timed out 1082 ms 132096 KB Time limit exceeded
91 Execution timed out 1089 ms 132096 KB Time limit exceeded
92 Execution timed out 1085 ms 132096 KB Time limit exceeded
93 Execution timed out 1088 ms 132096 KB Time limit exceeded
94 Execution timed out 1084 ms 132096 KB Time limit exceeded
95 Execution timed out 1095 ms 132096 KB Time limit exceeded
96 Execution timed out 1085 ms 132096 KB Time limit exceeded
97 Execution timed out 1086 ms 132096 KB Time limit exceeded
98 Execution timed out 1084 ms 132096 KB Time limit exceeded
99 Execution timed out 1086 ms 132096 KB Time limit exceeded
100 Execution timed out 1091 ms 132096 KB Time limit exceeded