#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int biggest_stadium(int N, std::vector<std::vector<int>> F) {
int cnt = 0;
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) cnt += (F[i][j] == 1);
if(!cnt) return N * N;
if(cnt == 1) {
int x=0, y=0;
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
if(F[i][j] == 1) x = i, y = j;
return N * N - min({ (x + 1) * (y + 1), (N - x) * (y + 1), (x + 1) * (N - y), (N - x) * (N - y) });
}
int ans = 0, n = N;
int mat[N+1][N+1];
vector<vector<int> > ver(n+1, vector<int>(n+1));
vector<vector<int> > hor(n+1, vector<int>(n+1));
memset(mat, 0, sizeof(mat));
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++) mat[i][j] = F[i-1][j-1];
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++) hor[i][j] = hor[i][j-1] + mat[i][j];
for(int j=1; j<=n; j++)
for(int i=1; i<=n; i++) ver[j][i] = ver[j][i-1] + mat[i][j];
vector<pair<int, int> > v;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++) if(!mat[i][j]) v.push_back({ i, j });
sort(v.begin(), v.end());
auto queryHor = [&](int row, int i, int j) {
return hor[row][max(i, j)] - hor[row][min(i, j)-1];
};
auto queryVer = [&](int col, int i, int j) {
return ver[col][max(i, j)] - ver[col][min(i, j)-1];
};
int m = v.size();
if(N <= 3) {
for(int s=0; s<(1<<m); s++) {
if(__builtin_popcount(s) <= ans) continue;
bool ok = 1;
for(int i=0; i<m; i++) {
if((s & (1 << i)) == 0) continue;
for(int j=i+1; j<m; j++) {
if((s & (1 << j)) == 0) continue;
bool ok1=1, ok2=1;
if(v[i].first == v[j].first) {
int x = max(v[j].second, v[i].second), y = min(v[j].second, v[i].second);
int p = hor[v[i].first][x] - hor[v[i].first][y-1];
if(p) {
ok1 = 0;
ok2 = 0;
ok = 0;
break;
}
}
if(v[i].second == v[j].second) {
int x = max(v[j].first, v[i].first), y = min(v[j].first, v[i].first);
int p = ver[v[i].second][x] - ver[v[i].second][y-1];
if(p) {
ok1 = 0;
ok2 = 0;
ok = 0;
break;
}
}
if(v[i].first != v[j].first && v[i].second != v[j].second) {
pair<int, int> a = v[i];
pair<int, int> b = v[j];
if(a.first > b.first) swap(a, b);
//right-UD
if(queryHor(a.first, a.second, b.second) || queryVer(b.second, a.first, b.first)) ok1 = 0;
//UP-right
if(queryVer(a.second, a.first, b.first) || queryHor(b.first, a.second, b.second)) ok2 = 0;
}
if(!ok1 && !ok2) {
ok = 0;
break;
}
}
}
if(ok) ans = max(ans, __builtin_popcount(s));
}
return ans;
}
//check full
bool ok = 1;
for(int i=0; i<m; i++) {
for(int j=i+1; j<m; j++) {
if(v[i].first == v[j].first) {
int x = min(v[i].second, v[j].second), y = max(v[i].second, v[j].second);
if(hor[v[i].first][y] - hor[v[i].first][x-1]) {
ok = 0;
break;
}
}
if(v[i].second == v[j].second) {
int x = min(v[i].first, v[j].first), y = max(v[i].first, v[j].first);
if(ver[v[i].second][y] - ver[v[i].second][x-1]) {
ok = 0;
break;
}
}
if(v[i].first != v[j].first && v[i].second != v[j].second) {
pair<int, int> a = v[i];
pair<int, int> b = v[j];
if(a.first > b.first) swap(a, b);
int ok1 = queryHor(a.first, a.second, b.second) + queryVer(b.second, a.first, b.first);
int ok2 = queryVer(a.second, a.first, b.first) + queryHor(b.first, a.second, b.second);
if(ok1 && ok2) {
ok = 0;
break;
}
}
}
}
return (ok ? m : m + 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
348 KB |
ok |
8 |
Correct |
16 ms |
2908 KB |
ok |
9 |
Correct |
252 ms |
36204 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
500 KB |
ok |
7 |
Correct |
0 ms |
500 KB |
ok |
8 |
Correct |
1 ms |
440 KB |
ok |
9 |
Correct |
1 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
344 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
500 KB |
ok |
8 |
Correct |
0 ms |
500 KB |
ok |
9 |
Correct |
1 ms |
440 KB |
ok |
10 |
Correct |
1 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Partially correct |
1 ms |
348 KB |
partial |
16 |
Partially correct |
0 ms |
348 KB |
partial |
17 |
Partially correct |
1 ms |
348 KB |
partial |
18 |
Partially correct |
1 ms |
436 KB |
partial |
19 |
Partially correct |
1 ms |
344 KB |
partial |
20 |
Correct |
1 ms |
348 KB |
ok |
21 |
Correct |
1 ms |
436 KB |
ok |
22 |
Partially correct |
0 ms |
348 KB |
partial |
23 |
Partially correct |
0 ms |
348 KB |
partial |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
0 ms |
348 KB |
partial |
26 |
Partially correct |
1 ms |
348 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
344 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
500 KB |
ok |
10 |
Correct |
0 ms |
500 KB |
ok |
11 |
Correct |
1 ms |
440 KB |
ok |
12 |
Correct |
1 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Partially correct |
1 ms |
348 KB |
partial |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
1 ms |
348 KB |
partial |
20 |
Partially correct |
1 ms |
436 KB |
partial |
21 |
Partially correct |
1 ms |
344 KB |
partial |
22 |
Correct |
1 ms |
348 KB |
ok |
23 |
Correct |
1 ms |
436 KB |
ok |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
0 ms |
348 KB |
partial |
26 |
Partially correct |
0 ms |
348 KB |
partial |
27 |
Partially correct |
0 ms |
348 KB |
partial |
28 |
Partially correct |
1 ms |
348 KB |
partial |
29 |
Partially correct |
1 ms |
348 KB |
partial |
30 |
Partially correct |
0 ms |
436 KB |
partial |
31 |
Partially correct |
1 ms |
856 KB |
partial |
32 |
Partially correct |
0 ms |
348 KB |
partial |
33 |
Partially correct |
1 ms |
348 KB |
partial |
34 |
Correct |
1 ms |
348 KB |
ok |
35 |
Correct |
1 ms |
348 KB |
ok |
36 |
Partially correct |
0 ms |
348 KB |
partial |
37 |
Partially correct |
0 ms |
348 KB |
partial |
38 |
Partially correct |
1 ms |
344 KB |
partial |
39 |
Partially correct |
1 ms |
348 KB |
partial |
40 |
Partially correct |
1 ms |
348 KB |
partial |
41 |
Partially correct |
1 ms |
348 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
344 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
500 KB |
ok |
10 |
Correct |
0 ms |
500 KB |
ok |
11 |
Correct |
1 ms |
440 KB |
ok |
12 |
Correct |
1 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Partially correct |
1 ms |
348 KB |
partial |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
1 ms |
348 KB |
partial |
20 |
Partially correct |
1 ms |
436 KB |
partial |
21 |
Partially correct |
1 ms |
344 KB |
partial |
22 |
Correct |
1 ms |
348 KB |
ok |
23 |
Correct |
1 ms |
436 KB |
ok |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
0 ms |
348 KB |
partial |
26 |
Partially correct |
0 ms |
348 KB |
partial |
27 |
Partially correct |
0 ms |
348 KB |
partial |
28 |
Partially correct |
1 ms |
348 KB |
partial |
29 |
Partially correct |
1 ms |
348 KB |
partial |
30 |
Partially correct |
0 ms |
436 KB |
partial |
31 |
Partially correct |
1 ms |
856 KB |
partial |
32 |
Partially correct |
0 ms |
348 KB |
partial |
33 |
Partially correct |
1 ms |
348 KB |
partial |
34 |
Correct |
1 ms |
348 KB |
ok |
35 |
Correct |
1 ms |
348 KB |
ok |
36 |
Partially correct |
0 ms |
348 KB |
partial |
37 |
Partially correct |
0 ms |
348 KB |
partial |
38 |
Partially correct |
1 ms |
344 KB |
partial |
39 |
Partially correct |
1 ms |
348 KB |
partial |
40 |
Partially correct |
1 ms |
348 KB |
partial |
41 |
Partially correct |
1 ms |
348 KB |
partial |
42 |
Partially correct |
30 ms |
8140 KB |
partial |
43 |
Partially correct |
28 ms |
7884 KB |
partial |
44 |
Partially correct |
59 ms |
8240 KB |
partial |
45 |
Partially correct |
192 ms |
8908 KB |
partial |
46 |
Partially correct |
34 ms |
8052 KB |
partial |
47 |
Execution timed out |
4534 ms |
8048 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 ms |
348 KB |
ok |
9 |
Correct |
16 ms |
2908 KB |
ok |
10 |
Correct |
252 ms |
36204 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
344 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
500 KB |
ok |
15 |
Correct |
0 ms |
500 KB |
ok |
16 |
Correct |
1 ms |
440 KB |
ok |
17 |
Correct |
1 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Partially correct |
1 ms |
348 KB |
partial |
23 |
Partially correct |
0 ms |
348 KB |
partial |
24 |
Partially correct |
1 ms |
348 KB |
partial |
25 |
Partially correct |
1 ms |
436 KB |
partial |
26 |
Partially correct |
1 ms |
344 KB |
partial |
27 |
Correct |
1 ms |
348 KB |
ok |
28 |
Correct |
1 ms |
436 KB |
ok |
29 |
Partially correct |
0 ms |
348 KB |
partial |
30 |
Partially correct |
0 ms |
348 KB |
partial |
31 |
Partially correct |
0 ms |
348 KB |
partial |
32 |
Partially correct |
0 ms |
348 KB |
partial |
33 |
Partially correct |
1 ms |
348 KB |
partial |
34 |
Partially correct |
1 ms |
348 KB |
partial |
35 |
Partially correct |
0 ms |
436 KB |
partial |
36 |
Partially correct |
1 ms |
856 KB |
partial |
37 |
Partially correct |
0 ms |
348 KB |
partial |
38 |
Partially correct |
1 ms |
348 KB |
partial |
39 |
Correct |
1 ms |
348 KB |
ok |
40 |
Correct |
1 ms |
348 KB |
ok |
41 |
Partially correct |
0 ms |
348 KB |
partial |
42 |
Partially correct |
0 ms |
348 KB |
partial |
43 |
Partially correct |
1 ms |
344 KB |
partial |
44 |
Partially correct |
1 ms |
348 KB |
partial |
45 |
Partially correct |
1 ms |
348 KB |
partial |
46 |
Partially correct |
1 ms |
348 KB |
partial |
47 |
Partially correct |
30 ms |
8140 KB |
partial |
48 |
Partially correct |
28 ms |
7884 KB |
partial |
49 |
Partially correct |
59 ms |
8240 KB |
partial |
50 |
Partially correct |
192 ms |
8908 KB |
partial |
51 |
Partially correct |
34 ms |
8052 KB |
partial |
52 |
Execution timed out |
4534 ms |
8048 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |