이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std ;
#define mid (l+r)/2
#define pb push_back
#define C continue
#define lb lower_bound
typedef long long ll ;
typedef vector < int > vi ;
#include "rect.h"
int n , m ;
int a [2509][2509] ;
int pre [2509][2509] ;
int Sum ( int i , int j , int k , int l ) {
int sum = 0 ;
sum += pre [j][l] ;
sum -= ( i ? pre [i-1][l] : 0 ) ;
sum -= ( k ? pre [j][k-1] : 0 ) ;
sum += ( i && k ? pre [i-1][k-1] : 0 ) ;
return sum ;
}
long long count_rectangles ( vector <vi> A ) {
n = A .size () ;
m = A [0] .size () ;
for ( int i = 0 ; i < n ; i ++ ) {
for ( int j = 0 ; j < m ; j ++ ) {
a [i][j] = A [i][j] ;
}
}
for ( int i = 0 ; i < n ; i ++ ) {
for ( int j = 0 ; j < m ; j ++ ) {
pre [i][j] = a [i][j] ;
pre [i][j] += ( i ? pre [i-1][j] : 0 ) ;
pre [i][j] += ( j ? pre [i][j-1] : 0 ) ;
pre [i][j] -= ( i && j ? pre [i-1][j-1] : 0 ) ;
}
}
ll ans = 0 ;
for ( int i = 1 ; i < n - 1 ; i ++ ) {
for ( int k = 1 ; k < m - 1 ; k ++ ) {
if ( a [i][k] == 1 ) C ;
int l = i , r = n - 1 ;
while ( r - l > 1 ) {
if ( Sum ( i , mid , k , k ) == 0 ) l = mid ;
else r = mid ;
}
int j = l ;
l = k , r = m - 1 ;
while ( r - l > 1 ) {
if ( Sum ( i , i , k , mid ) == 0 ) l = mid ;
else r = mid ;
}
if ( Sum ( i , j , k , l ) ) C ;
if ( Sum ( i , j , k - 1 , k - 1 ) != j - i + 1 ) C ;
if ( Sum ( i , j , l + 1 , l + 1 ) != j - i + 1 ) C ;
if ( Sum ( i - 1 , i - 1 , k , l ) != l - k + 1 ) C ;
if ( Sum ( j + 1 , j + 1 , k , l ) != l - k + 1 ) C ;
ans ++ ;
}
}
return ans ;
}
# | 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... |