이 제출은 이전 버전의 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][2] ;
int Sum ( int id , int l , int r , int t ) {
return pre [id][r][t] - ( l ? pre [id][l-1][t] : 0 ) ;
}
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 ++ ) {
int crnt = 0 ;
for ( int j = 0 ; j < m ; j ++ ) {
crnt += a [i][j] ;
pre [i][j][0] = crnt ;
}
}
for ( int j = 0 ; j < m ; j ++ ) {
int crnt = 0 ;
for ( int i = 0 ; i < n ; i ++ ) {
crnt += a [i][j] ;
pre [j][i][1] = crnt ;
}
}
ll ans = 0 ;
for ( int i = 1 ; i < n - 1 ; i ++ ) {
for ( int k = 1 ; k < m - 1 ; k ++ ) {
int l = i , r = n - 1 ;
while ( r - l > 1 ) {
if ( Sum ( k , i , mid , 1 ) == 0 ) l = mid ;
else r = mid ;
}
int j = l ;
l = k , r = m - 1 ;
while ( r - l > 1 ) {
if ( Sum ( i , k , mid , 0 ) == 0 ) l = mid ;
else r = mid ;
}
if ( Sum ( k - 1 , i , j , 1 ) != j - i + 1 ) C ;
if ( Sum ( l + 1 , i , j , 1 ) != j - i + 1 ) C ;
if ( Sum ( i - 1 , k , l , 0 ) != l - k + 1 ) C ;
if ( Sum ( j + 1 , k , l , 0 ) != 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... |