# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1114098 |
2024-11-18T07:47:43 Z |
adiyer |
Bomb (IZhO17_bomb) |
C++17 |
|
0 ms |
0 KB |
// 194.67
#pragma optimize ("g",on)
#pragma GCC optimize("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#include <bits/stdc++.h>
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define adiyer(); ios_base::sync_with_stdio(0); cin.tie(0);
#define bitcount(n) __builtin_popcountll(n)
#define puts(x) cout << (x ? "YES\n" : "NO\n");
#define ent (i == n ? '\n' : ' ')
#define all(x) x.begin(), x.end()
#define md ((l + r) >> 1)
#define rv(v) ((v << 1) | 1)
#define lv(v) (v << 1)
#define rs(v) rv(v), md + 1, r
#define ls(v) lv(v), l, md
#define len(s) (int) s.size()
#define yes { cout << "YES\n"; return; }
#define no { cout << "NO\n"; return; }
#define skip continue
#define pb push_back
#define S second
#define F first
#define ne !=
// #define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef pair < ll, ll > pll;
typedef vector < pair < ll, ll > > vpll;
const int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = 2.5e3 + 5;
const int K = 1e5 + 3;
const int MAX = 1e6;
const int mod = 998244353;
const long long inf = 2e9;
const ll o = 1;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll n, m, w, h;
ll a[N][N], pref[N][N];
int st[N][N];
char c;
ll get(ll l1, ll r1, ll l2, ll r2){
return pref[l2][r2] - pref[l1 - 1][r2] - pref[l2][r1 - 1] + pref[l1 - 1][r1 - 1];
}
bool f(ll W, ll H){
memset(st, 0, sizeof(st));
for(ll i = 1; i <= n; i++){
for(ll j = 1; j <= m; j++){
if(get(i, j, i + H - 1, j + W - 1) >= H * W){
st[i][j]++;
st[i + H][j]--;
st[i][j + W]--;
st[i + H][j + W]++;
}
st[i][j] += st[i - 1][j] + st[i][j - 1] - st[i - 1][j - 1];
if(a[i][j] && !st[i][j]) return 0;
}
}
return 1;
}
ll ff(ll H){
ll l = 0, r = m + 1;
while(r - l > 1){
if(f(md, H)) l = md;
else r = md;
}
return l * W;
}
void output(){
cin >> n >> m, w = m, h = n;
for(ll i = 1; i <= n; i++)
for(ll j = 1; j <= m; j++)
cin >> c, a[i][j] = c - '0';
for(ll i = 1; i <= n; i++)
for(ll j = 1; j <= m; j++)
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j];
ll l = 0, r = n + 1;
while(r - l > 2){
ll m1 = l + (r - l) / 3;
ll m2 = r - (r - l) / 3;
if(ff(m1) < ff(m2)) l = m1;
else r = m2;
}
ll ans = 0;
for(ll i = max(1ll, l - 20); i <= min(n, r + 20); i++) ans = max(ans, ff(i));
cout << ans;
}
const bool cases = 0;
signed main(){
// file("disrupt");
adiyer();
int tt = 1;
if(cases) cin >> tt;
for(int i = 1; i <= tt; i++){
// cout << "Case " << i << ":\n";
output();
// slow();
// stress();
}
}
Compilation message
bomb.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
2 | #pragma optimize ("g",on)
|
bomb.cpp: In function 'll ff(ll)':
bomb.cpp:87:13: error: 'W' was not declared in this scope
87 | return l * W;
| ^