This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int nt = 1;
vector<vector<int>> st_h, st_v;
int getvrange(int l, int r, int k, int x, int y, int i)
{
if (l > r) swap(l, r);
if (r < x || l > y) return 0;
if (x >= l && y <= r) return st_v[i][k];
int c = (x + y) / 2;
return getvrange(l, r, k*2, x, c, i) + getvrange(l, r, k*2|1, c+1, y, i);
}
int gethrange(int l, int r, int k, int x, int y, int i)
{
if (l > r) swap(l, r);
if (r < x || l > y) return 0;
if (x >= l && y <= r) return st_h[i][k];
int c = (x + y) / 2;
return gethrange(l, r, k*2, x, c, i) + gethrange(l, r, k*2|1, c+1, y, i);
}
int biggest_stadium(int N, vector<vector<int>> F)
{
int res = 0;
while (nt < N)
nt *= 2;
st_v = st_h = vector<vector<int>>(N, vector<int>(2*nt));
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
st_h[i][nt + j] = F[i][j];
st_v[i][nt + j] = F[j][i];
}
for (int j = nt - 1; j >= 1; j--)
{
st_h[i][j] = st_h[i][j*2] + st_h[i][j*2|1];
st_v[i][j] = st_v[i][j*2] + st_v[i][j*2|1];
}
}
int top;
int topl, topr;
for (int i = 0; i < N; i++)
{
if (st_h[i][1] == N) continue;
for (int j = 0; j < N; j++)
{
if (F[i][j]) continue;
if (gethrange(j, j + (N - st_h[i][1] - 1), 1, 0, nt - 1, i))
return -1;
top = i;
topl = j;
topr = j + (N - st_h[i][1] - 1);
break;
}
break;
}
int btm;
int btml, btmr;
for (int i = N-1; i >= 0; i--)
{
if (st_h[i][1] == N) continue;
for (int j = 0; j < N; j++)
{
if (F[i][j]) continue;
if (gethrange(j, j + (N - st_h[i][1] - 1), 1, 0, nt - 1, i))
return -1;
btm = i;
btml = j;
btmr = j + (N - st_h[i][1] - 1);
break;
}
break;
}
int lft;
int lft_up, lft_dwn;
for (int i = 0; i < N; i++)
{
if (st_v[i][1] == N) continue;
for (int j = 0; j < N; j++)
{
if (F[j][i]) continue;
if (getvrange(j, j + (N - st_v[i][1] - 1), 1, 0, nt - 1, i))
return -1;
lft = i;
lft_up = j;
lft_dwn = j + (N - st_v[i][1] - 1);
break;
}
break;
}
int right;
int right_up, right_dwn;
for (int i = N-1; i >= 0; i--)
{
if (st_v[i][1] == N) continue;
for (int j = 0; j < N; j++)
{
if (F[j][i]) continue;
if (getvrange(j, j + (N - st_v[i][1] - 1), 1, 0, nt - 1, i))
return -1;
right = i;
right_up = j;
right_dwn = j + (N - st_v[i][1] - 1);
break;
}
break;
}
if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
return -1;
int v = max(max(lft_up, right_up), min(lft_dwn, right_dwn));
if (!(topl >= btml && topr <= btmr) && !(topl <= btml && topr >= btmr))
return -1;
int h = max(max(topl, btml), min(topr, btmr));
int cnt = 0;
for (int x = 0; x < N; x++)
{
for (int y = 0; y < N; y++)
{
if (F[y][x])
continue;
cnt++;
}
}
if (N <= 500)
{
for (int x = 0; x < N; x++)
{
for (int y = 0; y < N; y++)
{
if (F[y][x])
continue;
{
bool b1 = getvrange(y, lft_up, 1, 0, nt - 1, x) || gethrange(x, lft, 1, 0, nt - 1, lft_up);
bool b2 = getvrange(y, lft_up, 1, 0, nt - 1, lft) || gethrange(x, lft, 1, 0, nt - 1, y);
if (b1 && b2)
return -1;
}
{
bool b1 = getvrange(y, right_up, 1, 0, nt - 1, x) || gethrange(x, right, 1, 0, nt - 1, right_up);
bool b2 = getvrange(y, right_up, 1, 0, nt - 1, right) || gethrange(x, right, 1, 0, nt - 1, y);
if (b1 && b2)
return -1;
}
{
bool b1 = getvrange(y, lft_dwn, 1, 0, nt - 1, x) || gethrange(x, lft, 1, 0, nt - 1, lft_dwn);
bool b2 = getvrange(y, lft_dwn, 1, 0, nt - 1, lft) || gethrange(x, lft, 1, 0, nt - 1, y);
if (b1 && b2)
return -1;
}
{
bool b1 = getvrange(y, right_dwn, 1, 0, nt - 1, x) || gethrange(x, right, 1, 0, nt - 1, right_dwn);
bool b2 = getvrange(y, right_dwn, 1, 0, nt - 1, right) || gethrange(x, right, 1, 0, nt - 1, y);
if (b1 && b2)
return -1;
}
{
bool b1 = getvrange(y, top, 1, 0, nt - 1, topl) || gethrange(x, topl, 1, 0, nt - 1, y);
bool b2 = getvrange(y, top, 1, 0, nt - 1, x) || gethrange(x, topl, 1, 0, nt - 1, top);
if (b1 && b2)
return -1;
}
{
bool b1 = getvrange(y, top, 1, 0, nt - 1, topr) || gethrange(x, topr, 1, 0, nt - 1, y);
bool b2 = getvrange(y, top, 1, 0, nt - 1, x) || gethrange(x, topr, 1, 0, nt - 1, top);
if (b1 && b2)
return -1;
}
{
bool b1 = getvrange(y, btm, 1, 0, nt - 1, btml) || gethrange(x, btml, 1, 0, nt - 1, y);
bool b2 = getvrange(y, btm, 1, 0, nt - 1, x) || gethrange(x, btml, 1, 0, nt - 1, btm);
if (b1 && b2)
return -1;
}
{
bool b1 = getvrange(y, btm, 1, 0, nt - 1, btmr) || gethrange(x, btmr, 1, 0, nt - 1, y);
bool b2 = getvrange(y, btm, 1, 0, nt - 1, x) || gethrange(x, btmr, 1, 0, nt - 1, btm);
if (b1 && b2)
return -1;
}
}
}
}
return cnt;
}
Compilation message (stderr)
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:30:9: warning: unused variable 'res' [-Wunused-variable]
30 | int res = 0;
| ^~~
soccer.cpp:131:9: warning: unused variable 'v' [-Wunused-variable]
131 | int v = max(max(lft_up, right_up), min(lft_dwn, right_dwn));
| ^
soccer.cpp:134:9: warning: unused variable 'h' [-Wunused-variable]
134 | int h = max(max(topl, btml), min(topr, btmr));
| ^
soccer.cpp:173:40: warning: 'lft_dwn' may be used uninitialized in this function [-Wmaybe-uninitialized]
173 | bool b2 = getvrange(y, lft_dwn, 1, 0, nt - 1, lft) || gethrange(x, lft, 1, 0, nt - 1, y);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:128:55: warning: 'lft_up' may be used uninitialized in this function [-Wmaybe-uninitialized]
128 | if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:206:81: warning: 'btmr' may be used uninitialized in this function [-Wmaybe-uninitialized]
206 | bool b1 = getvrange(y, btm, 1, 0, nt - 1, btmr) || gethrange(x, btmr, 1, 0, nt - 1, y);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:132:41: warning: 'btml' may be used uninitialized in this function [-Wmaybe-uninitialized]
132 | if (!(topl >= btml && topr <= btmr) && !(topl <= btml && topr >= btmr))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:194:81: warning: 'topr' may be used uninitialized in this function [-Wmaybe-uninitialized]
194 | bool b1 = getvrange(y, top, 1, 0, nt - 1, topr) || gethrange(x, topr, 1, 0, nt - 1, y);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:132:41: warning: 'topl' may be used uninitialized in this function [-Wmaybe-uninitialized]
132 | if (!(topl >= btml && topr <= btmr) && !(topl <= btml && topr >= btmr))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:158:83: warning: 'lft' may be used uninitialized in this function [-Wmaybe-uninitialized]
158 | bool b2 = getvrange(y, lft_up, 1, 0, nt - 1, lft) || gethrange(x, lft, 1, 0, nt - 1, y);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:207:78: warning: 'btm' may be used uninitialized in this function [-Wmaybe-uninitialized]
207 | bool b2 = getvrange(y, btm, 1, 0, nt - 1, x) || gethrange(x, btmr, 1, 0, nt - 1, btm);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:195:78: warning: 'top' may be used uninitialized in this function [-Wmaybe-uninitialized]
195 | bool b2 = getvrange(y, top, 1, 0, nt - 1, x) || gethrange(x, topr, 1, 0, nt - 1, top);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:181:40: warning: 'right_dwn' may be used uninitialized in this function [-Wmaybe-uninitialized]
181 | bool b2 = getvrange(y, right_dwn, 1, 0, nt - 1, right) || gethrange(x, right, 1, 0, nt - 1, y);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:128:55: warning: 'right_up' may be used uninitialized in this function [-Wmaybe-uninitialized]
128 | if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:165:87: warning: 'right' may be used uninitialized in this function [-Wmaybe-uninitialized]
165 | bool b2 = getvrange(y, right_up, 1, 0, nt - 1, right) || gethrange(x, right, 1, 0, nt - 1, y);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |