#include <stdio.h>
#include <vector>
int biggest_stadium( int N, std::vector<std::vector<int>> F ){
int nempty = 0, l, c, border, prev, minl, maxl, minc, maxc, max_fl, max_fc;
std::vector<int> fl( N, 0 ), fc( N, 0 );
minl = N;
maxl = -1;
minc = N;
maxc = -1;
for( l = 0 ; l < N ; l++ )
for( c = 0 ; c < N ; c++ )
if( !F[l][c] ){
nempty++;
fl[l]++;
fc[c]++;
minl = l < minl ? l : minl;
maxl = l > minl ? l : minl;
minc = c < minc ? c : minc;
maxc = c > minc ? c : minc;
}
for( l = 0 ; l < N ; l++ ){
prev = 1;
border = 0;
for( c = 0 ; c < N ; c++ ){
if( F[l][c] != prev ){
prev = F[l][c];
border++;
}
}
if( border > 2 )
return 1;
}
for( c = 0 ; c < N ; c++ ){
prev = 1;
border = 0;
for( l = 0 ; l < N ; l++ ){
if( F[l][c] != prev ){
prev = F[l][c];
border++;
}
}
if( border > 2 )
return 1;
}
max_fl = max_fc = 0;
for( l = 0 ; l < N ; l++ ){
max_fl = fl[l] > max_fl ? fl[l] : max_fl;
max_fc = fc[l] > max_fc ? fc[l] : max_fc;
}
if( maxl - minl + 1 != max_fl )
return 1;
if( maxc - minc + 1 != max_fc )
return 1;
return nempty;
// ignore the rest
// since initial condition is met now we can focus on couting reachable pairs
for( l = 0 ; l < N ; l++ )
for( c = 0 ; c < N ; c++ )
if( !F[l][c] ){
}
long long max_reachable = nempty;
max_reachable *= (nempty - 1);
max_reachable >>= 1; // (nempty choose 2)
long long reachable_pairs = 0;
for( l = 0 ; l < N ; l++ )
for( c = 0 ; c < N ; c++ )
if( !F[l][c] )
reachable_pairs += ((long long)fl[l]) * fc[c];
// all that is left is to count the pairs which allow 2 paths and remove them from the count
reachable_pairs -= nempty;
return reachable_pairs == max_reachable ? nempty : 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
wrong |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
wrong |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
partial |
2 |
Incorrect |
0 ms |
212 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
partial |
2 |
Incorrect |
0 ms |
212 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
partial |
2 |
Incorrect |
0 ms |
212 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
partial |
2 |
Incorrect |
0 ms |
212 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |